美文网首页
修改UIButton内部控件的尺寸

修改UIButton内部控件的尺寸

作者: 司机王 | 来源:发表于2016-03-13 23:21 被阅读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的尺寸

相关文章

网友评论

      本文标题:修改UIButton内部控件的尺寸

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