且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将背景图像添加到UILabel

更新时间:2023-12-05 22:44:58

尝试使用代码:

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.