Last active
August 27, 2016 09:57
-
-
Save jenhausu/3ded70a64af5a62ff1399032d1012608 to your computer and use it in GitHub Desktop.
客製化 UITableViewCell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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