将背景图像添加到UILabel [英] Adding Background image to UILabel

查看:122
本文介绍了将背景图像添加到UILabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iPhone应用程序中将背景图像添加到UILabel.我试图通过IB来做,但是没有结果.

How can I add a background image to a UILabel in an iPhone Application. I've tried to do it through IB but with no result.

推荐答案

尝试使用代码:

Objective-C:

theLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blah"]];

快捷键:

theLabel.backgroundColor = UIColor(patternImage: UIImage(named: "blah")!)

或在标签后面放置UIImageView(不建议).

Or place an UIImageView behind the label (not recommended).

更新:不建议将UIImageView放在标签后面,因为那样您就必须管理两个视图.但是,如果您必须执行仅UIImageView可以执行的操作,那么这仍然是一种好方法.我怀疑您的应用实际上可以通过这种方式更好地运行.

Update: placing an UIImageView behind a label was not recommended because then you would have to manage two views. But if you must do something that only an UIImageView can do this is still a good approach. I suspect that your app will actually run better this way.

这篇关于将背景图像添加到UILabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆