// // TLBottleButton.m // TLChat // // Created by 李伯坤 on 16/2/22. // Copyright © 2016年 李伯坤. All rights reserved. // #import "TLBottleButton.h" @interface TLBottleButton () @property (nonatomic, strong) UIImageView *iconImageView; @property (nonatomic, strong) UILabel *textLabel; @end @implementation TLBottleButton - (id)initWithType:(TLBottleButtonType)type title:(NSString *)title iconPath:(NSString *)iconPath { if (self = [super init]) { [self addSubview:self.iconImageView]; [self addSubview:self.textLabel]; [self p_addMasonry]; self.type = type; self.title = title; self.iconPath = iconPath; } return self; } - (void)setTitle:(NSString *)title { _title = title; [self.textLabel setText:title]; } - (void)setIconPath:(NSString *)iconPath { _iconPath = iconPath; [self.iconImageView setImage:[UIImage imageNamed:iconPath]]; } #pragma mark - Private Methods - - (void)p_addMasonry { [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.and.left.and.right.mas_equalTo(self); make.bottom.mas_equalTo(self.textLabel.mas_top).mas_offset(9); }]; [self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.and.right.mas_equalTo(self); make.bottom.mas_equalTo(self).mas_offset(-3); }]; } #pragma mark - Getter - - (UIImageView *)iconImageView { if (_iconImageView == nil) { _iconImageView = [[UIImageView alloc] init]; } return _iconImageView; } - (UILabel *)textLabel { if (_textLabel == nil) { _textLabel = [[UILabel alloc] init]; [_textLabel setFont:[UIFont systemFontOfSize:12.0f]]; [_textLabel setTextAlignment:NSTextAlignmentCenter]; [_textLabel setTextColor:[UIColor whiteColor]]; } return _textLabel; } @end