How to style UITextview to like Rounded Rect text field?

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

    Here is my solution:

    - (void)viewDidLoad {
        [super viewDidLoad];
    
    
        self.textView.text = self.messagePlaceholderText;
        self.textView.layer.backgroundColor = [[UIColor whiteColor] CGColor];
        self.textView.layer.borderColor = [[[UIColor grayColor] colorWithAlphaComponent:0.3] CGColor];
        self.textView.layer.borderWidth = 0.5;
        self.textView.layer.cornerRadius = 5.5f;
        self.textView.layer.masksToBounds = YES;
        self.textView.textColor = [[UIColor grayColor] colorWithAlphaComponent:0.4];
    }
    
    - (void)textViewDidBeginEditing:(UITextView *)textView {
        if (textView == self.tvMessage) {
            // Delete placeholder text
            if ([self.textView.text isEqualToString:self.messagePlaceholderText]) {
                self.textView.text = @"";
                self.textView.textColor = [UIColor blackColor];
            }
        }
    }
    
    - (void)textViewDidEndEditing:(UITextView *)textView {
        if (textView == self.tvMessage) {
            // Write placeholder text
            if (self.textView.text.length == 0) {
                self.textView.text = self.messagePlaceholderText;
                self.textView.textColor = [[UIColor grayColor] colorWithAlphaComponent:0.4];
            }
        }
    }
    

提交回复
热议问题