You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

113 lines
2.7 KiB

//
// WTListButtonCell.m
// iosMemoryPalace
//
// Created by yuklng on 2017/5/9.
// Copyright © 2017年 yuklng. All rights reserved.
//
#import "WTListButtonCell.h"
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r,g,b) RGBA(r,g,b,1.0f)
@interface WTListButtonCell()
@property (nonatomic,strong) UIView* cellBackgroundView;
@end
@implementation WTListButtonCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self initData];
[self initSubView];
[self configAutoLayout];
}
return self;
}
-(void)initData{
_textNormalColor =[UIColor grayColor];
_textHighlightedColor =[UIColor orangeColor];
_backgroundNormalColor =[UIColor clearColor];
_backgroundHighlighteColor =RGB(231, 230, 238);
}
-(void)initSubView{
[self cellBackgroundView];
self.textLabel.textColor =_textNormalColor;
}
-(UIView*)cellBackgroundView{
if (_cellBackgroundView) {
return _cellBackgroundView;
}else{
_cellBackgroundView =[[UIView alloc] init];
_cellBackgroundView.backgroundColor =_backgroundNormalColor;
_cellBackgroundView.layer.cornerRadius =5.0;
_cellBackgroundView.layer.masksToBounds=YES;
[self.contentView addSubview:_cellBackgroundView];
return _cellBackgroundView;
}
}
-(void)configAutoLayout{
// _cellBackgroundView.frame =(CGRect){
// .origin.x =0,
// .origin.y =0,
// .size.width =self.contentView.frame.size.width -0,
// .size.height =self.contentView.frame.size.height -0
// };
CGFloat margin =3;
_cellBackgroundView.frame =CGRectMake(margin, margin, self.frame.size.width-margin*2, self.frame.size.height-margin*2);
}
-(void)layoutSubviews {
[super layoutSubviews];
[self configAutoLayout];
// [self setSelected:self.selected animated:YES];
}
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
if (selected) {
self.textLabel.textColor = _textHighlightedColor;
self.cellBackgroundView.backgroundColor =_backgroundHighlighteColor;
}else{
self.textLabel.textColor =_textNormalColor;
self.cellBackgroundView.backgroundColor =_backgroundNormalColor;
}
[self setNeedsDisplay];
}
@end