Mad Burea Mad Burea - 4 months ago 15
iOS Question

Bottom Border in UiTextfield

Actually i have created Border in Textfiled by using this code.

CALayer *bottomBorder = [CALayer layer];

bottomBorder.frame = CGRectMake(0.0f, self.frame.size.height - 1, self.layer.frame.size.width, 1.0f);

bottomBorder.backgroundColor = self.BorderColor.CGColor;

[self.layer addSublayer:bottomBorder];


Everything is working fine upto iphone 5s but when i run in iphone 6 and above it's border size decrease. like if width of textfield is 120 border show only upto 100 . Don't know how to deal with That. Please Guide me through it

Answer

If you want to deal with CALayer then Try this following life cycle method.

 -(void)viewDidLayoutSubviews
    {
       CALayer *bottomBorder = [CALayer layer];

        bottomBorder.frame = CGRectMake(0.0f, self.frame.size.height - 1, self.layer.frame.size.width, 1.0f);

        bottomBorder.backgroundColor = self.BorderColor.CGColor;

        [self.layer addSublayer:bottomBorder];

    }