Reputation: 31
We can set color to text in UILabel. But can we set image to text in UILabel? Can you help me? Thanks all!
Upvotes: 2
Views: 1975
Reputation: 4750
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];
If you want your textColor as Image then please do this
[lbl setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"button_select.png"]]];
Upvotes: 1
Reputation: 318944
If you want to replicate the image you linked to using a UILabel
, you can do that by setting the label's text and backgroundColor. Then you use
UIColor colorWithPatternImage:for the orange color pattern. Then use that color for the label's
textColor`.
Upvotes: 0
Reputation: 3208
UILabel
is only for text. If you want an image, use an UIImageView
.
Upvotes: 0