UITextField中的缩进

时间:2012-05-23 15:15:14

标签: objective-c ios xcode uitextfield indentation

For example, I want the "test" text a little bit right, what property should I set?

UITextView缩进问题:

例如,我希望“测试”文本有点正确,我应该设置什么属性?

3 个答案:

答案 0 :(得分:12)

试试这个

    UIView *paddingView           = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 20)];
    self.yourtextField.leftView             = paddingView;
    self.yourtextField.leftViewMode         = UITextFieldViewModeAlways;

答案 1 :(得分:8)

创建子类并覆盖textRectForBounds:editingRectForBounds:。您的新实现可能类似于

- (CGRect)textRectForBounds:(CGRect)bounds;
{
    return CGRectInset([super textRectForBounds:bounds], 10.f, 0.f);
}

- (CGRect)editingRectForBounds:(CGRect)bounds;
{
    return CGRectInset([super editingRectForBounds:bounds], 10.f, 0.f);
}

答案 2 :(得分:1)

试试这个简单的方法......

textfield.frame = CGRectMake(textfield.frame.origin.x+10, textfield.frame.origin.y, textfield.frame.size.width, textfield.frame.size.height);