How to style UITextview to like Rounded Rect text field?

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

    Edit: You have to import

    #import 
    

    for using corner radius.

    Try this it will work for sure

    UITextView* txtView = [[UITextView alloc] initWithFrame:CGRectMake(50, 50, 300, 100)];
    txtView.layer.cornerRadius = 5.0;
    txtView.clipsToBounds = YES;
    

    As Rob figured it out setting the if you want the border color to be similar as UITextField then you need to change the border width to 2.0 and color to gray by adding the following line

    [textView.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]]; 
    [textView.layer setBorderWidth:2.0];
    

提交回复
热议问题