美文网首页基础知识
iOS xib 加载view 修改不了frame的问题

iOS xib 加载view 修改不了frame的问题

作者: 半杯故事 | 来源:发表于2018-01-15 10:02 被阅读70次

    方法一:

    @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;
    }
    
    

    相关文章

      网友评论

        本文标题:iOS xib 加载view 修改不了frame的问题

        本文链接:https://www.haomeiwen.com/subject/kfjroxtx.html