UITextField Only Top And Bottom Border

后端 未结 11 994
温柔的废话
温柔的废话 2020-12-07 22:46

I currently have a regular border. I would like to only have a top and bottom border.

How do I accomplish this?

Using the UITextField<

11条回答
  •  清歌不尽
    2020-12-07 23:27

    You can also add views to the top and bottom to use as borders.

    // Top border
    UIView *topBorder = [[UIView alloc]
        initWithFrame:CGRectMake(0,
                                 0,
                                 textfield.frame.size.width,
                                 4.0f)];
    topBorder.backgroundColor = [UIColor colorWithRed:160/255.0f
                                                green:160/255.0f
                                                 blue:160/255.0f
                                                alpha:1.0f];
    [textfield addSubview:topBorder];
    
    // Bottom border
    UIView *bottomBorder = [[UIView alloc]
        initWithFrame:CGRectMake(0,
                                 textfield.frame.origin.y +
                                     textfield.frame.size.height - 4.0f,
                                 textfield.frame.size.width,
                                 4.0f)];
    bottomBorder.backgroundColor = [UIColor colorWithRed:160/255.0f
                                                   green:160/255.0f
                                                    blue:160/255.0f
                                                   alpha:1.0f];
    [textfield addSubview:bottomBorder];
    

提交回复
热议问题