0

我正在开发一个应用程序。我将文本文件的边框宽度设置为 1o 基础,不符合我的要求。所以现在文本文件的第一个字符将被边框颜色隐藏。所以请告诉我如何设置光标注视位置UITextField。

4

2 回答 2

2

创建 UITextField 的子类并使用它。

在您的子类中覆盖这些方法。他们将在您的文本字段中从左侧添加空间。

// placeholder text reposition
- (CGRect)textRectForBounds:(CGRect)bounds {
     return CGRectInset(bounds, 10, 0);
}

// text reposition
- (CGRect)editingRectForBounds:(CGRect)bounds {
     return CGRectInset(bounds, 10, 0);
}
于 2013-09-20T07:10:36.823 回答
2

添加UIview边框并添加UITextField到里面UIView

 UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0,0, frame.size.width, frame.size.height)];
        [baseView setBackgroundColor:[UIColor clearColor]];
        [baseView setUserInteractionEnabled:YES];
        [baseView setClipsToBounds:NO];
        baseView.layer.borderColor =[UIColor lightGrayColor].CGColor;// UIColorFromRGB(0Xcccccc).CGColor;
        baseView.layer.borderWidth = 1.0f;
        [self addSubview:baseView];
UITextField* txtField = [[UITextField alloc]initWithFrame:CGRectMake(1, 1, frame.size.width-2,  frame.size.height-2)];
        [txtField setBackgroundColor:[UIColor whiteColor]];
[baseView addSubview:txtField];
于 2013-09-20T07:15:09.393 回答