首页 > 其他 > 详细

IOS- 自定义 UIButton

时间:2014-02-27 21:01:50      阅读:447      评论:0      收藏:0      [点我收藏+]

#pragma mark init方法内部默认会调用initWithFrame:

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        // 里面的图片居中

        self.imageView.contentMode = UIViewContentModeCenter;

        // 里面的文字居中

        self.titleLabel.textAlignment = NSTextAlignmentCenter;

        // 文字字体

        self.titleLabel.font = [UIFont systemFontOfSize:12];

    }

    return self;

}

 

#pragma mark 当按钮达到高亮状态的时候会调用,并且默认会在这个方法中进行高亮处理

- (void)setHighlighted:(BOOL)highlighted { }

 

#pragma mark 设置内部imageView的frame

- (CGRect)imageRectForContentRect:(CGRect)contentRect

{

    CGFloat imgW = contentRect.size.width;

    CGFloat imgH = contentRect.size.height * kImageScale;

    return CGRectMake(0, 0, imgW, imgH);

}

 

#pragma mark 设置内部titleLabel的frame

- (CGRect)titleRectForContentRect:(CGRect)contentRect

{

    CGFloat titleW = contentRect.size.width;

    CGFloat titleY = contentRect.size.height * kImageScale;

    CGFloat titleH = contentRect.size.height - titleY;

   

    return CGRectMake(0, titleY, titleW, titleH);

}

IOS- 自定义 UIButton,布布扣,bubuko.com

IOS- 自定义 UIButton

原文:http://www.cnblogs.com/mcj-coding/p/3570373.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!