3

角の丸い UITextField を iOS のテーブル ビューに読み込もうとしています。ほとんどの場合、すべてが正常に機能しています。ただし、角の半径のプロパティにより、一番左の文字が部分的に切り取られます。UITextField に入力されたテキストにマージンを設定して、適切に表示する方法はありますか? これが私のコードです:

        textInput = [[UITextField alloc] init];
        textInput.backgroundColor = [UIColor whiteColor];
        textInput.placeholder = @"example@gmail.com";
        textInput.textColor = [UIColor blackColor];
        textInput.keyboardType = UIKeyboardTypeEmailAddress;
        textInput.returnKeyType = UIReturnKeyDone;

        [[textInput layer] setBorderColor:[[UIColor whiteColor] CGColor]];
        [[textInput layer] setBorderWidth:2.3];
        [[textInput layer] setCornerRadius:15];
        [textInput setClipsToBounds: YES];
        [textInput setDelegate:self];

    [self.contentView addSubview:textInput];
        [textInput release];
4

3 に答える 3

1

私は解決策を考え出しました。からサブクラス化されたカスタムテキストフィールドを作成しましたUITextField

#import "CR_customTextField.h"

@implementation CR_customTextField

- (CGRect)textRectForBounds:(CGRect)bounds {
    int margin = 10;
    CGRect inset = CGRectMake(bounds.origin.x + margin, bounds.origin.y, bounds.size.width - margin, bounds.size.height);
    return inset;
}

- (CGRect)editingRectForBounds:(CGRect)bounds {
    int margin = 10;
    CGRect inset = CGRectMake(bounds.origin.x + margin, bounds.origin.y, bounds.size.width - margin, bounds.size.height);
    return inset;
}

@end
于 2013-01-09T19:14:10.727 に答える
0

これを使って

[textInput sizeToFit];

それはあなたを助けるかもしれません

于 2012-12-29T06:28:14.623 に答える