子类UIView或UIViewController [英] Subclass UIView or UIViewController

查看:94
本文介绍了子类UIView或UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个部分",在其下面有一个图像和一些文本.

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

我应该子类化UIView还是UIViewController? 我在考虑UIView,因为它不知道要显示什么图像或文本,只是两者都会存在. 另外,如果它是UIView,我应该以哪种方法将子视图(UIImageView和UILabel)添加为子视图?还是应该在不使用drawRect中使用UIImageView或UILabel的情况下绘制文本和图像?

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?

推荐答案

  • 子类
  • initWithFrame:
  • 中添加子视图(UIImageView和UILabel)
  • layoutSubviews
  • 中布置子视图
  • 如果需要,可以在drawRect:中进行其他自定义绘图
    • Subclass UIView
    • Add the subviews (UIImageView and UILabel) in initWithFrame:
    • Layout the subviews in layoutSubviews
    • Do additional custom drawing in drawRect:, if needed
    • 这篇关于子类UIView或UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆