您的位置:首页 > 其它

[一句秒懂]按钮button同时设置图片和文字

2016-06-17 00:00 288 查看
摘要: 自定义button

代码简介:

自定义按钮

#import "YLButton.h"

@interface YLButton ()

@property (nonatomic, strong)UILabel *label;
@property (nonatomic, strong)UIImageView *imageV;

@end

@implementation YLButton

- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.titleLabel.font = [UIFont systemFontOfSize:13];
[self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self setImage:[UIImage imageNamed:@"120A"] forState:UIControlStateNormal];
}
return self;
}

- (void)layoutSubviews {
[super layoutSubviews];

self.imageView.y = self.height * 0.15;
self.imageView.height = self.width;
self.imageView.width = self.imageView.height;
self.imageView.centerX = self.width * 0.5;

self.titleLabel.x = 0;
self.titleLabel.y = self.imageView.y + self.height;
self.titleLabel.height = self.height - self.titleLabel.y;
self.titleLabel.width = self.width;
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息