我可以NSAttributedString使用转义的换行符(@"\n")创建一个多行.使用iOS 7,我现在可以嵌入一个UIImage内部属性字符串(via NSTextAttachment).
我注意到每当我将attributedTexta 设置为UILabel带有嵌入图像的多行属性字符串时,实际显示的行数与标签的高度成反比.例如,当标签的高度为80时,会出现两条线; 当高度大约为100时,只出现第二条线; 当高度约为130时,什么都没有出现.
尝试将多个UILabel并排放置在a UITableViewCell内并使标签与单元格高度(垂直)增长时发生此问题.
任何人都可以解释为什么会这样吗?有没有人知道不涉及使UILabel变小的解决方法?
示例代码:
@implementation SOViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableAttributedString *text1 = [[NSMutableAttributedString alloc] init];
[text1 appendAttributedString:[[NSAttributedString alloc] initWithString:@"Line 1\n"]];
[text1 appendAttributedString:[[NSAttributedString alloc] initWithString:@"Line 2"]];
UIImage *image = [UIImage imageNamed:@"17x10"]; //some PNG image (17px by 10px)
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = image;
attachment.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
NSMutableAttributedString *text2 = [[NSMutableAttributedString …Run Code Online (Sandbox Code Playgroud)