Skip to content

Instantly share code, notes, and snippets.

@jenhausu
Last active August 27, 2016 09:57
Show Gist options
  • Save jenhausu/3ded70a64af5a62ff1399032d1012608 to your computer and use it in GitHub Desktop.
Save jenhausu/3ded70a64af5a62ff1399032d1012608 to your computer and use it in GitHub Desktop.
客製化 UITableViewCell
#import "CCardTableViewCell.h"
@implementation CCardTableViewCell
- (UIView *)card
{
if (!_card) {
_card = [[UIView alloc] init];
}
return _card;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
[self.card.layer setCornerRadius:15];
[self addSubview:self.card];
self.card.sd_layout.bottomSpaceToView(self, 20).centerXEqualToView(self).widthIs(self.frame.size.width - 20 * 2).heightIs(174);
if (selected) {
self.card.backgroundColor = [UIColor colorWithRed:0.44 green:0.75 blue:0.27 alpha:0.2];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView registerClass:[CCardTableViewCell class] forCellReuseIdentifier:@"Cell"];
CCardTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
// Card
cell.card = [[UIView alloc] init];
[cell.card.layer setCornerRadius:15];
cell.card.backgroundColor = indexPath.row == 0 ? [UIColor colorWithRed:0.44 green:0.75 blue:0.27 alpha:0.1] : [ColorConfig backgoundGrayColor];
[cell addSubview:cell.card];
cell.card.sd_layout.bottomSpaceToView(cell, 20).centerXEqualToView(cell).widthIs(cell.frame.size.width - 20 * 2).heightIs(174);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment