方法一:
@interface AddTextView ()
{
CGRect myframe;
}
@end
@implementation AddTextView
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
NSArray *nibs=[[NSBundle mainBundle]loadNibNamed:@"AddTextView" owner:nil options:nil];
self=[nibs objectAtIndex:0];
myframe = frame;
NSLog(@"gao = %f",frame.size.height);
}
return self;
}
-(void)drawRect:(CGRect)rect{
self.frame = myframe;
}
@end
方法二:
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
UIView *view = [[[NSBundle mainBundle]loadNibNamed:@"AddTextView" owner:self options:nil] firstObject];
view.backgroundColor = [UIColor redColor];
view.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
self.backgroundColor = [UIColor yellowColor];
self.frame = frame;
[self addSubview:view];
}
return self;
}
网友评论