How to style UITextview to like Rounded Rect text field?

后端 未结 20 2313
深忆病人
深忆病人 2020-11-28 00:36

I am using a text view as a comment composer.

In the properties inspector I can\'t find anything like a border style property so that I can make use a rounded rect,

20条回答
  •  遥遥无期
    2020-11-28 01:25

    I wanted the real deal, so I add UIImageView as a subview of the UITextView. This matches the native border on a UITextField, including the gradient from top to bottom:

    textView.backgroundColor = [UIColor clearColor];
    UIImageView *borderView = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, textView.frame.size.width, textView.frame.size.height)];
    borderView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    UIImage *textFieldImage = [[UIImage imageNamed:@"TextField.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 8, 15, 8)];
    borderView.image = textFieldImage;
    [textField addSubview: borderView];
    [textField sendSubviewToBack: borderView];
    

    These are the images I use:

    enter image description here enter image description here

提交回复
热议问题