Subclass UIView or UIViewController

2019-03-16 23:24发布

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?

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-03-16 23:48

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

查看更多
beautiful°
3楼-- · 2019-03-16 23:59
  • Subclass UIView
  • Add the subviews (UIImageView and UILabel) in initWithFrame:
  • Layout the subviews in layoutSubviews
  • Do additional custom drawing in drawRect:, if needed
查看更多
登录 后发表回答