标签(图片底部)和文本字段(顶部)具有相同的attributionText。但请看下划线。文本字段中的那些只有一个像素高。这看起来很可怕。有谁知道造成这种情况的原因或如何预防?
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
UITextField* textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 600, 200)];
NSMutableAttributedString* string = [[NSMutableAttributedString alloc]initWithString:@"The quick brown fox jumps"];
NSNumber* underlineNumber = [NSNumber numberWithInteger:NSUnderlineStyleSingle];
UIFont* font = [UIFont systemFontOfSize: 50];
[string addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, string.length)];
for (NSInteger i=0; i<20; i++) {
if (i%3==0) {
[string addAttribute:NSUnderlineStyleAttributeName value:underlineNumber range:NSMakeRange(i, 1)];
}
}
textField.backgroundColor = [UIColor whiteColor];
textField.attributedText = string;
[self addSubview:textField];
UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(100, 400, 600, 200)];
label.attributedText = string;
label.font = font;
label.backgroundColor = [UIColor whiteColor];
[self addSubview:label];
}
return self;
}
答案 0 :(得分:4)
标签使用自定义渲染样式来绘制下划线,遗憾的是它与UITextField使用的下划线不同,UITextField在编辑时使用WebKit进行渲染,在静态时使用Core Text进行渲染。请提交bugreporter.apple.com的错误。谢谢!