修改UIButton内部控件的尺寸

2016-03-13  本文已影响132人  司机王

比如修改UIButton里UIImage的尺寸,需要重写- (CGRect)imageRectForContentRect:(CGRect)contentRect方法,其中contentRect就是这个UIButton的尺寸

- (CGRect)imageRectForContentRect:(CGRect)contentRect{

    CGFloat imageW = 40; // 这里修改你想改的尺寸

    CGFloat imageH = 40;
    
    CGFloat imageX = 40;
    
    CGFloat imageY = 40;
    
    return CGRectMake(imageX, imageY, imageW, imageH);
}

同理,
-(CGRect)titleRectForContentRect:(CGRect)contentRect就是改变内部UILabel的尺寸

上一篇 下一篇

猜你喜欢

热点阅读