如何设置背景图片的文本到UIlabel? [英] How to set background image for text into UIlabel?

查看:82
本文介绍了如何设置背景图片的文本到UIlabel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在UILabel中为文本设置颜色.但是我们可以在UILabel中将图像设置为文本吗?你能帮助我吗?谢谢大家!

We can set color to text in UILabel. But can we set image to text in UILabel? Can you help me? Thanks all!

推荐答案

UILabel *lbl  = [[UILabel alloc]initWithFrame:CGRectMake(20, 220, 200, 30)];

[lbl setText:@"Hello"];

[lbl setTextColor:[UIColor yellowColor]];

[lbl setBackgroundColor:[UIColor redColor]];

if you need to set image for your UILabel, you can try like this:

[lbl setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@""]]];

[self.view addSubview:lbl];

如果您希望将textColor作为图像,请执行此操作

[lbl setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"button_select.png"]]];

这篇关于如何设置背景图片的文本到UIlabel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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