1

ラベル (画像の下) とテキスト フィールド (上) は同じ attributedText を持っています。しかし、下線を見てください。テキスト フィールド内のものは、高さが 1 ピクセルしかありません。これはひどく見えます。誰がこれを引き起こしているのか、またはそれを防ぐ方法を知っていますか?

- (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;
}

ここに画像の説明を入力

4

1 に答える 1

4

ラベルはカスタム レンダリング スタイルを使用して下線を描画しますが、これは残念ながら、編集時に WebKit を使用してレンダリングし、静的時にレンダリングするために Core Text を使用する UITextField で使用されるものとは異なります。bugreporter.apple.com でバグを報告してください。ありがとう!

于 2012-12-24T05:09:50.443 に答える