gpt4 book ai didi

ios - 用背景图片覆盖 UIView

转载 作者:可可西里 更新时间:2023-11-01 04:28:04 29 4
gpt4 key购买 nike

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

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com