I am trying to create a custom view with a white border around it to act as a container for several subviews.
I can create this by adding a UIView object in Interface Builder, and setting the border in User Defined Runtime Attributes, but this doesn't render in Interface Builder.
That's okay, and it's even considered normal, but this year, a new attribute was introduced: IB_DESIGNABLE
. This allows custom views to be rendered in real-time in Interface Builder, but requires a subclass to be created, and custom drawing to be done in -(void)drawRect:(CGRect)rect
.
I want to try using this feature, but are there any reasons not to? I've heard that drawRect
is not a performance friendly method, why is that? Is changing a view's appearance using Interface Builder to set attributes such as color, size, etc. better than using drawRect
to accomplish the same thing? Any info would be appreciated.
P.S. How are different properties between code and IB handled? For example, if I set the frame of a view to be CGRectMake(0, 0, 100, 100)
but position and size it differently in IB, which takes precedence? Also, Is drawRect
the right method to set properties such as border color and width? Sorry for the seemingly basic questions, I've gotten used to using Interface Builder for everything, and don't remember much about programmatically drawing views, layers and whatnot.