简体   繁体   中英

how to set this type of bottom border textfield?

How to set only bottom border textfield ? what kind of coding i have used...

I want this type of output screen

我想要这种类型的输出屏幕

This is my coding

border = [CALayer layer];
    CGFloat borderWidth = 2;
    border.borderColor = [UIColor whiteColor].CGColor;
    border.frame = CGRectMake(0, firstname.frame.size.height - borderWidth, firstname.frame.size.width, firstname.frame.size.height);
    border.borderWidth = borderWidth;
    [firstname.layer addSublayer:border];
    firstname.layer.masksToBounds = YES;

If you want to do this without using UITableView ,

Try following code:

CALayer *yourborder = [CALayer layer];
CGFloat borderWidth = 2;
yourborder.borderColor = [UIColor darkGrayColor].CGColor;
yourborder.frame = CGRectMake(0, firstname.frame.size.height - borderWidth, firstname.frame.size.width, firstname.frame.size.height);
yourborder.borderWidth = borderWidth;
[firstname.layer addSublayer:yourborder];
firstname.layer.masksToBounds = YES;

Use UITableView for this kind of form and for bottom border use line separator of tableview and use below type of textFiled for your desire output.

txtName.borderStyle = UITextBorderStyleNone;

Hope this will help you.

Create extension on UIView

     //extension
     extension UIView {

          func bottomBorder(color color: UIColor, width: CGFloat) {
                let border = CALayer()
                border.backgroundColor = color.CGColor
                border.frame = CGRectMake(0, self.frame.size.height - width, self.frame.size.width, width)
                border.masksToBounds = true
                self.layer.addSublayer(border)
           }
    }

call this method like

firstname.bottomBorder(color: UIColor.whiteColor(), width: 2)

for the effect you are trying you can use UITableview alternatively

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM