Is there a way to display into the text label of a UILabel an "ANY icon + text", assuming that the icon is an Apple symbol or Zapf Dingbats font caracter ?
That way localizing the text would automaticaly center the whole thing and adjust the icon position into the label depending on its size.
Something like this : http://www.chocolatechip-ui.com/screenshots/buttons.png
I would have an image for the background and overlay onto it the icon+text label.
I DON'T want to put an image in a button.
EDIT I limit the question just for UILabel as asking the same thing to work for UIButton generate lots of out of context answers.
看一下这个快速的项目: https : //github.com/anatoliyv/SMIconLabel如果可以将符号放到UIImage中,它应该可以完全满足您的要求。
you can do it with attributedText (iOS >= 7)
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:@"icon.png"];
NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
NSMutableAttributedString *myString= [[NSMutableAttributedString alloc] initWithString:@"text bla bla bla"];
[myString appendAttributedString:attachmentString];
self.label.attributedText = myString;
如果将UIButton样式设置为custom,并将图标图像设置为Background(不是图像),则设置时将能够看到标题。
You could create a view which suites your needs and overlay a custom invisible button.
As an alternative you could subclass UIButton
.
试试: label.backgroundColor = [UIColor colorWithPatternImage:image];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.