ios如何向文本框添加底部边框和侧面设计 [英] ios How to add bottom border and side design to textfield
本文介绍了ios如何向文本框添加底部边框和侧面设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想添加底部边框,如下图所示,我已成功添加了底线,但我没有出现细线
I would like to add bottom border like as below image , I have added botom line successfully but i'm not getting side small lines
这是我的代码
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;
推荐答案
您需要添加3层(底部,左侧和右侧).检查以下代码.
You need to add 3 layers (Bottom, Left and Right). Check below code.
CALayer *bottomBorder = [CALayer layer], *leftBorder = [CALayer layer], *rightBorder = [CALayer layer];
CGFloat thickness = 1.0f;
CGFloat side_height = 6.0f;
leftBorder.frame = CGRectMake(0, textField.frame.size.height - side_height, thickness, textField.frame.size.height - 1);
rightBorder.frame = CGRectMake(textField.frame.size.width - 1, textField.frame.size.height - side_height, thickness, textField.frame.size.height - 1);
bottomBorder.frame = CGRectMake(0, textField.frame.size.height-1, textField.frame.size.width, thickness);
bottomBorder.backgroundColor = [UIColor lightGrayColor].CGColor;
leftBorder.backgroundColor = [UIColor lightGrayColor].CGColor;
rightBorder.backgroundColor = [UIColor lightGrayColor].CGColor;
[textField.layer addSublayer:bottomBorder];
[textField.layer addSublayer:leftBorder];
[textField.layer addSublayer:rightBorder];
这篇关于ios如何向文本框添加底部边框和侧面设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文