怎样让外界无法改变自定义view的尺寸大小

 重写setFrame和setBounds方法即可。

+ (instancetype)testView
{
    return [[self alloc] init];
}

- (void)setFrame:(CGRect)frame
{
    frame.size = CGSizeMake(100, 100);
    [super setFrame:frame];
}

- (void)setBounds:(CGRect)bounds
{
    bounds.size = CGSizeMake(100, 100);
    [super setBounds:bounds];
}
原文地址:https://www.cnblogs.com/yintingting/p/4544671.html