iphone - 如何在 UITextField 中设置光标起始位置

标签 iphone ios uitextfield

<分区>

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

最佳答案

添加带边框的UIview,并在UIView中添加UITextField

 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];

关于iphone - 如何在 UITextField 中设置光标起始位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18910411/

上一篇:iphone - 获取地址簿数据,它的代码在模拟器上运行但没有运行 iPhone 设备。

下一篇:ios - 为什么不将 View 添加到此 UI Animator 中?

相关文章:

iphone - 登录注销 View Controller

iphone - 在 GCD block 中绘制图像时卡顿

android - Appstore 多个名称

ios - IB 中圆形图标的 UIImageView 子类

swift - 带小数点键盘的 UITextfield 中的自动逗号

ios - 如何改变 UITextField 的形状?

ios - WKWebview 上的 ApplePay

objective-c - 直接通过名称绑定(bind) SQLite 参数

ios - 动态创建应用程序图标

iphone - 在 Iphone 应用程序中发表评论