How to style UITextview to like Rounded Rect text field?

后端 未结 20 2317
深忆病人
深忆病人 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

    If you want to keep your controller code clean, you can subclass UITextView like below, and change the class name in the Interface Builder.

    RoundTextView.h

    #import 
    @interface RoundTextView : UITextView
    @end
    

    RoundTextView.m

    #import "RoundTextView.h"
    #import 
    @implementation RoundTextView
    -(id) initWithCoder:(NSCoder *)aDecoder {
        if (self = [super initWithCoder:aDecoder]) {
            [self.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.333] CGColor]];
            [self.layer setBorderWidth:1.0];
            self.layer.cornerRadius = 5;
            self.clipsToBounds = YES;
        }
        return self;
    }
    @end
    

提交回复
热议问题