是否可以在不使用 Interface Builder 中的 UIImageView
的情况下用图像覆盖 UIView
?
如果没有,您将如何在代码中完成相同的任务?
最佳答案
来自 UIView 文档:
Image-based backgrounds - For views that display relatively static content, consider using a UIImageView object with gesture recognizers instead of subclassing and drawing the image yourself. Alternatively, you can also use a generic UIView object and assign your image as the content of the view’s CALayer object.
使用第二个选项,将 someView 设置为 yourImage.png 的背景:
someView.layer.contents = (id)[[UIImage imageNamed:@"yourImage.png"] CGImage];
关于ios - 用背景图片覆盖 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7942155/