ios - 用背景图片覆盖 UIView

标签 ios uiview uikit uiimageview uiimage

是否可以在不使用 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/

相关文章:

ios - 如何在 Cocoa Touch 中切换 View ?

ios - 从 XIB 创建的 UICollectionViewCell 在拖放过程中会导致闪烁

ios - 是否可以复制 Realm 对象?

ios - 绘制 UIView 并转换为 UIImage

ios - CGAffineTransform Make Translation 在 iOS 6 上导致 View 旋转

iphone - UIView 性能 : opaque, backgroundColor,clearsContextBeforeDrawing?

ios - 嵌入在 UITableViewCell 中的动态、自定义布局 UICollectionView

ios - iPad模拟器和外屏

iOS NSStream 套接字读取 TCP 不稳定和截断

iphone - 如何处理 ios 连接丢失