Bordered UITextView

后端 未结 14 2231
一个人的身影
一个人的身影 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条回答
  •  猫巷女王i
    2020-12-04 10:40

    As of iOS 8 and Xcode 6, I now find the best solution is to subclass UITextView and mark the subclass as an IB_DESIGNABLE, which will allow you to view the border in storyboard.

    Header:

    #import 
    
    IB_DESIGNABLE
    
    @interface BorderTextView : UITextView
    
    @end
    

    Implementation:

    #import "BorderTextView.h"
    
    @implementation BorderTextView
    
    - (void)drawRect:(CGRect)rect
    {
        self.layer.borderWidth = 1.0;
        self.layer.borderColor = [UIColor blackColor].CGColor;
        self.layer.cornerRadius = 5.0f;
    }
    
    @end
    

    Then just drag out your UITextView in storyboard and set its class to BorderTextView

提交回复
热议问题