0

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.

kumowoon1025
  • 201
  • 1
  • 9
  • Hey there, just a suggestion -- you might want to re-word some of this to be more concise (less broad). As it is, it's a lot of questions to answer, and much of it is opinion-based. – brandonscript Dec 07 '14 at 21:44
  • drawRect is one way of adding a border. You can also just add the subview in `layoutSubviews` - I suggest you watch the video from WWDC that demonstrates how to use IBDesignable – Paulw11 Dec 07 '14 at 22:39
  • If you ask this question you better stick to Interface Builder. – pronebird Dec 07 '14 at 23:13

0 Answers0