initWithFrame
来源:互联网 发布:苏亚星软件远程开机 编辑:程序博客网 时间:2024/05/17 01:36
1. initWithFrame方法是什么?
initWithFrame方法用来初始化并返回一个新的视图对象,根据指定的CGRect(尺寸)。
当然,其他UI对象,也有initWithFrame方法,但是,我们以UIView为例,来搞清楚initWithFrame方法。
2.什么时候用initWithFrame方法?
简单的说,我们用编程方式申明,创建UIView对象时,使用initWithFrame方法。
在此,我们必须搞清楚,两种方式来进行初始化UIView。
1.使用 Interface Builder 方式。
这种方式,就是使用nib文件。通常我们说的“拖控件” 的方式。
实际编程中,我们如果用Interface Builder 方式创建了UIView对象。(也就是,用拖控件的方式)
那么,initWithFrame方法方法是不会被调用的。因为nib文件已经知道如何初始化该View。(因为,我们在拖该view的时候,就定义好了长、宽、背景等属性)。
这时候,会调用initWithCoder方法,我们可以用initWithCoder方法来重新定义我们在nib中已经设置的各项属性。
2.使用编程方式。
就是我们声明一个UIView的子类,进行“手工”编写代码的方式。
实际编程中,我们使用编程方式下,来创建一个UIView或者创建UIView的子类。这时候,将调用initWithFrame方法,来实例化UIView。
特别注意,如果在子类中重载initWithFrame方法,必须先调用父类的initWithFrame方法。在对自定义的UIView子类进行初始化操作。
比如:
- (id)initWithFrame:(CGRect)frame{
}
0 0
- initWithFrame
- initWithFrame
- initWithFrame
- initWithFrame:reuseIdentifier:
- initWithFrame调用
- init initwithframe
- init initwithframe
- WebView::initWithFrame调用栈
- initWithCoder与initWithFrame
- initWithFrame: 和 initWithCoder: 区别
- initWithFrame 和 initWithCoder
- init: 和 initWithFrame:
- initWithFrame 和 initWithCoder 差别
- initwithcoder和 initwithframe 区别?
- initWithFrame 和 initWithCoder
- initWithFrame 和 initWithCoder
- ios学习--initWithFrame方法
- initWithNib init initWithCoder initWithFrame
- HDOJ 4493 Tutor
- AIDE文件系统高级入侵检测
- 三元闭包与强弱联系
- 浅谈RGB
- TransactionScope使用说明
- initWithFrame
- [LeetCode] Interleaving String 交叉字符串
- EditPlus使用
- Android开发教程:shape和selector的结合使用
- SQL连接的基本划分
- 海豚实习-实现两个大数相乘
- 十道思想难题
- 一路成长
- IOS之地图和定位应用开发