views:

51

answers:

2

I want to make a "section" which has an image and some text below it.

Should I be subclassing UIView or UIViewController? I'm thinking UIView as it won't know what image or what text to display, just that there will be both. Also if it is UIView, what method do I add the subviews (UIImageView and UILabel) in as subviews? Or should I draw the the text and image, without using UIImageView or UILabel in drawRect?

A: 
  • Subclass UIView
  • Add the subviews (UIImageView and UILabel) in initWithFrame:
  • Layout the subviews in layoutSubviews
  • Do additional custom drawing in drawRect:, if needed
Michele Balistreri
By layout the subviews, do you mean set the frames? Is there any example code on the net somewhere? And What exactly is custom drawing?
Jonathan
Yes I mean exactly setting the frame. This is useful when the size of the UILabel or UIImageView is determined by its content, as layoutSubviews is invoked prior to first drawing, and every time setNeedsLayout is invoked on the view. Custom drawing I mean if you need to add some other elements that are not contained in any subview.
Michele Balistreri
A: 

Use UIView, because it's simpler. I would use UIViewController if I had multiple sections, such as tabs or something.

ertemplin