【问题标题】:UITextField input text position [duplicate]UITextField输入文本位置[重复]
【发布时间】:2011-08-09 00:54:50
【问题描述】:

你好 我正在制作这样的自定义 UITextField :

_textField.borderStyle=UITextBorderStyleNone;
_textField.backgroundColor = _color;
_textField.layer.borderColor = [[UIColor grayColor]CGColor];
_textField.layer.borderWidth = 1.0f;
_textField.layer.cornerRadius = 8.0f;
_textField.font = [UIFont systemFontOfSize:14];

我得到的结果是(图片网址)http://img402.imageshack.us/img402/4330/questionyd.jpg

问题:如何将输入文本稍微向右移动,使其不接触边框? 我想我必须定义一些 .frame 属性,但不知道是哪一个。

谢谢! 路易斯

【问题讨论】:

    标签: objective-c uitextfield


    【解决方案1】:

    您可以将leftView 属性设置为空的UIView 和一个小框架,将leftViewMode 属性设置为UITextFieldViewModeAlways,这样您的占位符视图将始终被使用。

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 5)];
    _textField.leftView = view;
    _textField.leftViewMode = UITextFieldViewModeAlways;
    [view release];
    

    【讨论】:

      【解决方案2】:

      您可以尝试创建自己的UITextField 子类并覆盖该方法:

      -(CGRect)textRectForBounds:(CGRect)bounds
      

      设置您自己的界限,而不是处理默认值。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-21
        • 2013-01-15
        • 2013-02-20
        • 2023-03-12
        相关资源
        最近更新 更多