以编程方式在标签背景中设置图像
我有一个标签(实际上有很多标签),现在我想要在标签的背景中放置一个图像(同一图像),以便向用户显示我的标签中写入的文本。如何以编程方式做到这一点?
I have a label (many labels in fact) now I want an image in the background of my label (same image) so that text writtenin my label is shown to user. How to do it programmatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法就是简单地将 UIImageView 放在 UILabel 后面。如果你想让它更强大,你可以创建一个 UILabel 子类,它公开一个方法或属性来设置图像背景,并将图像添加到自身。
The simplest way would just be to simply layer a UIImageView behind the UILabel. If you wanted to make it more robust you could make a UILabel subclass that exposes a method or property to set the image background and it would add the image to itself.