【发布时间】:2016-05-04 19:57:33
【问题描述】:
我正在开发一个应用程序,它的每行都有textView 的底部边框,我在谷歌和 StackOverflow 上找不到关于这个问题的任何答案。所以我决定问一个问题,我有这个 textview:
我正在以编程方式进行,所以请不要给我故事板示例,谢谢
【问题讨论】:
标签: ios swift uitextview border line
我正在开发一个应用程序,它的每行都有textView 的底部边框,我在谷歌和 StackOverflow 上找不到关于这个问题的任何答案。所以我决定问一个问题,我有这个 textview:
我正在以编程方式进行,所以请不要给我故事板示例,谢谢
【问题讨论】:
标签: ios swift uitextview border line
var textview:UITextView=UITextView()
for var i:Int = 20 ; i <= Int(textview.frame.size.height) ; i = i + 20 // set 20 you line distance .. change your chooice
{
let border = CALayer()
border.borderColor = UIColor.grayColor().CGColor
border.frame = CGRectMake(0, CGFloat(i), textview.frame.size.width*1.5 , 1.0)
border.borderWidth = 1.0
textview.layer.addSublayer(border)
textview.layer.masksToBounds = true
}
【讨论】:
您可以使用此代码
-(void)setBorderView:(UITextField*)textField
{
UIView *borderView = [[UIView alloc]init];
borderView.backgroundColor = [UIColor clearColor];
CGRect frameRectEmail=textField.frame;
NSLogVariable(textField);
borderView.layer.borderWidth=1;
borderView.layer.borderColor=[customColor colorWithHexString:@"8c8b90"].CGColor;
borderView.layer.cornerRadius=5;
borderView.layer.masksToBounds=YES;
UIView *topBorder = [[UIView alloc]init];
topBorder.backgroundColor = [customColor colorWithHexString:@"1e1a36"];
CGRect frameRect=textField.frame;
frameRect.size.height=CGRectGetHeight(textField.frame)/1.5;
topBorder.frame = frameRect;
frameRectEmail.size.width=frameRect.size.width;
[borderView setFrame:frameRectEmail];
[_textFieldBackGroundView addSubview:borderView];
[_textFieldBackGroundView addSubview:topBorder];
[_textFieldBackGroundView addSubview:textField];
}
【讨论】: