【发布时间】:2014-11-24 04:40:03
【问题描述】:
我想将NSTextAttachment 图像附加到我的属性字符串并使其垂直居中。
我使用以下代码来创建我的字符串:
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:DDLocalizedString(@"title.upcomingHotspots") attributes:attrs];
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [[UIImage imageNamed:@"help.png"] imageScaledToFitSize:CGSizeMake(14.f, 14.f)];
cell.textLabel.attributedText = [str copy];
但是,图像似乎与单元格顶部的 textLabel 对齐。
如何更改绘制附件的矩形?
【问题讨论】:
-
我有一个类别类,用于将 NSString 与 UIImage 结合使用,反之亦然。 github.com/Pradeepkn/TextWithImage享受。
标签: ios objective-c swift uilabel nstextattachment