Files
benmy--tlchat/TLChat/Modules/Scanner/TLScannerViewController/Views/TLScannerButton.m
T
2026-07-13 12:35:01 +08:00

95 lines
2.3 KiB
Objective-C

//
// TLScannerButton.m
// TLChat
//
// Created by 李伯坤 on 16/2/25.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLScannerButton.h"
@interface TLScannerButton ()
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *textLabel;
@end
@implementation TLScannerButton
- (id)initWithType:(TLScannerType)type title:(NSString *)title iconPath:(NSString *)iconPath iconHLPath:(NSString *)iconHLPath
{
if (self = [super init]) {
[self addSubview:self.iconImageView];
[self addSubview:self.textLabel];
[self p_addMasonry];
self.type = type;
self.title = title;
self.iconPath = iconPath;
self.iconHLPath = iconHLPath;
}
return self;
}
- (void)setTitle:(NSString *)title
{
_title = title;
[self.textLabel setText:title];
}
- (void)setIconPath:(NSString *)iconPath
{
_iconPath = iconPath;
[self.iconImageView setImage:[UIImage imageNamed:iconPath]];
}
- (void)setIconHLPath:(NSString *)iconHLPath
{
_iconHLPath = iconHLPath;
[self.iconImageView setHighlightedImage:[UIImage imageNamed:iconHLPath]];
}
- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
[self.iconImageView setHighlighted:selected];
[self.textLabel setHighlighted:selected];
}
#pragma mark - Private Methods -
- (void)p_addMasonry
{
[self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.and.left.and.right.mas_equalTo(self);
make.height.mas_equalTo(self.iconImageView.mas_width);
}];
[self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.right.mas_equalTo(self);
make.bottom.mas_equalTo(self);
}];
}
#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]];
[_textLabel setHighlightedTextColor:[UIColor colorGreenDefault]];
}
return _textLabel;
}
@end