iOS UITextField left border

JOAOSerraJOAOSerra PTMember ✭✭

Simple question... How can I add a left border to my UITextField's on iOS?

Posts

  • adamkempadamkemp USInsider, Developer Group Leader mod

    There is nothing as simple as just setting a property to make a border show up only on the left, but you can get the same effect a few ways. You can set a custom background image or you can use another view. To use another view you just need to do this:

    1. Create a UIView with a border (view.Layer.BorderColor = UIColor.Red.CGColor; view.Layer.BorderWidth = 2;
    2. Size it so that it is the height of the text field and a width of 0.
    3. Position it to the left of the text field.
  • JOAOSerraJOAOSerra PTMember ✭✭
    var native = (UITextField)Control;
                native.Layer.CornerRadius = 0;
                native.Layer.MasksToBounds = true;
                native.BorderStyle = UITextBorderStyle.None;
                native.Layer.BorderWidth = 5;
                native.Layer.BorderColor = native.BackgroundColor.CGColor;
    

    this makes the text to go behind the border

Sign In or Register to comment.