16 Mar 2018

How to give a Bottom line to a TextField iOS...

How to give a Bottom line to a TextField iOS...

To give a underline to textField (Only bottom border) line use the following code:



Here we use CALayer class to achieve it,

-(void)underlineToTextField:(UITextField *)txtField
{
CALayer *border = [CALayer layer];
CGFloat borderWidth = 0.8f;
    border.borderColor = [UIcolor greenColor].CGColor;
    border.frame = CGRectMake(0, text.frame.size.height -      borderWidth, ([[UIScreen mainScreen] bounds].size.width)-32, text.frame.size.height);
    border.borderWidth = borderWidth;
    [text.layer addSublayer:border];
    text.layer.masksToBounds = YES;
}

Call the method for which TextField you want to show underline like below,

[self underlineToTextField:textField];



2 comments:

  1. Thanks for sharing the useful blog about giving Bottomline to the Text field with example.

    Android Application Development Company

    ReplyDelete
  2. all mobile Solutions

    About Mobile Solutions,Smart phone unlocked,Android Tools,Gsm Unlock Tips,All In One Box,Smart Phone Repair,tips and Tutorial.

    https://www.alltips24a2z.com/

    ReplyDelete

Recent Posts

Codable demo

Link: https://www.dropbox.com/s/kw7c1kgv1628bh7/codableDemo.zip?dl=0