重写setFrame和setBounds方法即可。
+ (instancetype)testView
{
return [[self alloc] init];
} - (void)setFrame:(CGRect)frame
{
frame.size = CGSizeMake(, );
[super setFrame:frame];
} - (void)setBounds:(CGRect)bounds
{
bounds.size = CGSizeMake(, );
[super setBounds:bounds];
}