一般自定义View
- -
(id)initWithFrame:(CGRect)frame - {
-
self = [super initWithFrame:frame]; -
if (self) { -
// add subviews -
} -
return self; - }
还有种 是自己画。 重载
- (void)drawRect:(CGRect)rect {
}
如果
所以嘞
在你项目中 新建个 类
在新建个XIB
在XIB 中 选中View
最后 改下 View 的Autosizing 项
要使用这个UIView
平常我就通过 这个静态方法 来实例化
- +(LKTextView
*)instanceTextView - {
-
NSArray* nibView = [[NSBundle mainBundle] loadNibNamed:@"LKTextView" owner:nil options:nil]; -
return [nibView objectAtIndex:0]; - }
- -(id)initWithCoder:(NSCoder
*)aDecoder - {
-
self = [super initWithCoder:aDecoder]; -
if(self) -
{ -
//you init -
} -
return self; - }
使用的方法:
- LKTextView*
text = [LKTextView instanceTextView]; -
text.frame = CGRectMake(100, 100, text.frame.size.width, text.frame.size.height); -
text.textView.text = @"input "; -
[self.view addSubview:text];