代码简介:
自定义按钮
#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