码迷,mamicode.com
首页 > 其他好文 > 详细

自定义Button 图片在上面文字在下面

时间:2016-01-06 11:48:02      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

#import "buttonCustom.h"
#define KimageW 30
#define KtitleH 21
#define Kpadding 10
@interface buttonCustom()

@end

@implementation buttonCustom

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return self;
}

//set title
- (void)setTitle:(NSString *)title forState:(UIControlState)state{
    [super setTitle:title forState:state];
   
}

//set image
- (void)setImage:(UIImage *)image forState:(UIControlState)state
{
    [super setImage:image forState:state];
    
}


//custom title rect
- (CGRect)titleRectForContentRect:(CGRect)contentRect{
    return CGRectMake(0 , Kpadding *2 , self.bounds.size.width, 21 );
}

//custom image rect
- (CGRect)imageRectForContentRect:(CGRect)contentRect{
    return CGRectMake(0 , Kpadding ,self.bounds.size.width , KimageW);
}
@end

 

自定义Button 图片在上面文字在下面

标签:

原文地址:http://www.cnblogs.com/Mantis-man/p/5104656.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!