ios如何在textfield中添加底部边框和边框设计

时间:2017-02-20 17:12:23

标签: ios objective-c uitextfield

我想添加底部边框,如下图所示,我已经成功添加了botom线,但我没有得到旁边的小线

enter image description here

这是我的代码

CALayer *border = [CALayer layer];
CGFloat borderWidth = 1;
border.borderColor = [UIColor lightGrayColor].CGColor;
border.frame = CGRectMake(0, textField.frame.size.height - borderWidth, textField.frame.size.width, textField.frame.size.height);
border.borderWidth = borderWidth;
[textField.layer addSublayer:border];
textField.layer.cornerRadius=30;
textField.layer.masksToBounds = YES;

2 个答案:

答案 0 :(得分:1)

我刚刚为UITextField编写了边框课程,我希望它能为你提供帮助。

class GUTextField: UITextField {

    public var bottomLineView:UIView?
    @IBInspectable var lineColor = UIColor.gray

    //MARK:- UiTextfield Draw Method Override
    override func draw(_ rect: CGRect) {
        super.draw(rect)
        self.frame = CGRect(x:self.frame.minX, y:self.frame.minY, width:rect.width, height:rect.height)
        addBottomLine()
    }

    //MARK:- ADD Bottom Line
    private func addBottomLine(){
        bottomLineView?.removeFromSuperview()
        bottomLineView = UIView(frame: CGRect(x:0, y:self.frame.height-1, width:self.frame.width, height:2))
        bottomLineView?.backgroundColor = lineColor;
        bottomLineView?.isHidden = true
        if bottomLineView != nil {
            self.addSubview(bottomLineView!)
        }
    }
}

答案 1 :(得分:1)

您需要添加3个图层(底部,左侧和右侧)。检查以下代码。

user_train=np.loadtxt(user_train)
train_label=np.loadtxt(train_label)
print('imputing training data ...')

imp=Imputer(missing_values='NaN',strategy='mean',axis=1)
imp.fit(user_train)
user_train=imp.transform(user_train)
print(user_train.shape,train_label.shape)
print('normalizing training data ...')
print(user,i)

normalizer=preprocessing.Normalizer().fit(user_train)
user_train_nor=normalizer.transform(user_train)
print('writing trainiing data')

output=(save_fea+'%s_tag_train_nor.txt'%(user))

svm_rank_format=dump_svmlight_file(user_train_nor,train_label,output,zero_based=False)