本文介绍了UITextfield borderColor和文本字段一侧的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本字段设置如下:

I have a text field setup like so:

textField.borderStyle = UITextBorderStyleLine;
textField.layer.borderColor = [[UIColor greenColor] CGColor];
textField.layer.borderWidth= 10.0f;'

但它是否可能只有左侧边框较大,颜色不同?
或者我是否必须使用我想要的颜色和位置来定位drawRect?

But is it possible to just have a larger border on the left side and it be a different color?Or do I have to position a drawRect there with the color I want and position?

推荐答案

尝试使用此代码可能有帮助你添加自定义TextFiled的边框左侧像Bellow: -

try with this code might be help's you add Border left side of custom TextFiled like Bellow:-

- (void)viewDidLoad
{

    [super viewDidLoad];
    UIView *bottomBorder = [[UIView alloc]
                            initWithFrame:CGRectMake(0,0,4,txtField.frame.size.height)];
    bottomBorder.backgroundColor = [UIColor redColor];
    [txtField addSubview:bottomBorder];

}

此Bellow委托代码在textfield中的某个空格后启动

This Bellow delegate Code for start after some space in textfield

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
    textField.leftView = paddingView;
    textField.leftViewMode = UITextFieldViewModeAlways;
}

OUTPUT看起来像这样: -

OUTPUT look like this:-

这篇关于UITextfield borderColor和文本字段一侧的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 21:01