Bordered UITextView

后端 未结 14 2182
一个人的身影
一个人的身影 2020-12-04 10:11

I want to have a thin gray border around a UITextView. I have gone through the Apple documentation but couldn\'t find any property there. Please help.

14条回答
  •  离开以前
    2020-12-04 10:20

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

    enter image description here

    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 png images I use, and a jpg representation:

    @1x

    @2x

    enter image description here

提交回复
热议问题