GeezerVison is showing github.com — Selected background image view · zhmios/RETableViewManager@77d2fb8
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: RETableViewManager/Cells/RETableViewDateTimeCell.m +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | // | 8 | 8 |
| 9 | 9 | #import "RETableViewDateTimeCell.h" | | 10 | +#import "RETableViewManager.h" | 10 | 11 |
| 11 | 12 | @implementation RETableViewDateTimeCell | 12 | 13 |
| 13 | 14 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier | 14 | 15 | { | 15 | 16 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; | 16 | 17 | if (self) { | 17 | | - self.selectionStyle = UITableViewCellSelectionStyleBlue; | 18 | 18 | self.textLabel.backgroundColor = [UIColor clearColor]; | 19 | 19 | } | 20 | 20 | return self; | @@ -23,7 +23,7 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus | 23 | 23 | - (void)cellDidLoad | 24 | 24 | { | 25 | 25 | [super cellDidLoad]; | 26 | | - | | 26 | + self.selectionStyle = self.tableViewManager.style.defaultCellSelectionStyle; | 27 | 27 | } | 28 | 28 |
| 29 | 29 | - (void)cellWillAppear | |
Collapse file Copy file name to clipboardExpand all lines: RETableViewManager/RETableViewCell.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 33 | 33 | @interface RETableViewCell : UITableViewCell <REActionBarDelegate> | 34 | 34 |
| 35 | 35 | @property (strong, readonly, nonatomic) UIImageView *backgroundImageView; | | 36 | +@property (strong, readonly, nonatomic) UIImageView *selectedBackgroundImageView; | 36 | 37 | @property (assign, readwrite, nonatomic) NSInteger row; | 37 | 38 | @property (assign, readwrite, nonatomic) NSInteger sectionIndex; | 38 | 39 | @property (weak, readwrite, nonatomic) UITableView *parentTableView; | |
Collapse file Copy file name to clipboardExpand all lines: RETableViewManager/RETableViewCell.m +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -55,6 +55,13 @@ - (void)cellDidLoad | 55 | 55 | _backgroundImageView = [[UIImageView alloc] init]; | 56 | 56 | [self.backgroundView addSubview:_backgroundImageView]; | 57 | 57 | } | | 58 | + | | 59 | + if ([self.tableViewManager.style hasCustomSelectedBackgroundImage]) { | | 60 | + self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.contentView.bounds]; | | 61 | + self.selectedBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | | 62 | + _selectedBackgroundImageView = [[UIImageView alloc] init]; | | 63 | + [self.selectedBackgroundView addSubview:_selectedBackgroundImageView]; | | 64 | + } | 58 | 65 | } | 59 | 66 |
| 60 | 67 | - (void)cellWillAppear | @@ -90,6 +97,22 @@ - (void)layoutSubviews | 90 | 97 |
| 91 | 98 | _backgroundImageView.frame = CGRectMake(0, 0, _backgroundImageView.image.size.width, _backgroundImageView.image.size.height); | 92 | 99 | } | | 100 | + | | 101 | + if ([self.tableViewManager.style hasCustomSelectedBackgroundImage]) { | | 102 | + if (self.row == 0 && self.section.items.count == 1) | | 103 | + _selectedBackgroundImageView.image = [self.tableViewManager.style selectedBackgroundImageForCellType:RETableViewCellSingle]; | | 104 | + | | 105 | + if (self.row == 0 && self.section.items.count > 1) | | 106 | + _selectedBackgroundImageView.image = [self.tableViewManager.style selectedBackgroundImageForCellType:RETableViewCellFirst]; | | 107 | + | | 108 | + if (self.row > 0 && self.row < self.section.items.count - 1 && self.section.items.count > 2) | | 109 | + _selectedBackgroundImageView.image = [self.tableViewManager.style selectedBackgroundImageForCellType:RETableViewCellMiddle]; | | 110 | + | | 111 | + if (self.row == self.section.items.count - 1 && self.section.items.count > 1) | | 112 | + _selectedBackgroundImageView.image = [self.tableViewManager.style selectedBackgroundImageForCellType:RETableViewCellLast]; | | 113 | + | | 114 | + _selectedBackgroundImageView.frame = CGRectMake(0, 0, _selectedBackgroundImageView.image.size.width, _selectedBackgroundImageView.image.size.height); | | 115 | + } | 93 | 116 | } | 94 | 117 |
| 95 | 118 | - (void)updateActionBarNavigationControl | |
Collapse file Copy file name to clipboardExpand all lines: RETableViewManager/RETableViewCellStyle.h +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,14 +34,20 @@ typedef enum _RETableViewCellType { | 34 | 34 |
| 35 | 35 | @interface RETableViewCellStyle : NSObject { | 36 | 36 | NSMutableDictionary *_backgroundImages; | | 37 | + NSMutableDictionary *_selectedBackgroundImages; | 37 | 38 | } | 38 | 39 |
| 39 | 40 | @property (strong, readwrite, nonatomic) UIFont *textFieldFont; | 40 | 41 | @property (assign, readwrite, nonatomic) CGSize textFieldPositionOffset; | 41 | 42 | @property (assign, readwrite, nonatomic) CGFloat cellHeight; | | 43 | +@property (assign, readwrite, nonatomic) UITableViewCellSelectionStyle defaultCellSelectionStyle; | 42 | 44 |
| 43 | 45 | - (BOOL)hasCustomBackgroundImage; | 44 | 46 | - (UIImage *)backgroundImageForCellType:(RETableViewCellType)cellType; | 45 | 47 | - (void)setBackgroundImage:(UIImage *)image forCellType:(RETableViewCellType)cellType; | 46 | 48 |
| | 49 | +- (BOOL)hasCustomSelectedBackgroundImage; | | 50 | +- (UIImage *)selectedBackgroundImageForCellType:(RETableViewCellType)cellType; | | 51 | +- (void)setSelectedBackgroundImage:(UIImage *)image forCellType:(RETableViewCellType)cellType; | | 52 | + | 47 | 53 | @end |
Collapse file Copy file name to clipboardExpand all lines: RETableViewManager/RETableViewCellStyle.m +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,8 +34,10 @@ - (id)init | 34 | 34 | return nil; | 35 | 35 |
| 36 | 36 | _backgroundImages = [[NSMutableDictionary alloc] init]; | | 37 | + _selectedBackgroundImages = [[NSMutableDictionary alloc] init]; | 37 | 38 | _textFieldFont = [UIFont systemFontOfSize:16]; | 38 | 39 | _cellHeight = 44; | | 40 | + _defaultCellSelectionStyle = UITableViewCellSelectionStyleBlue; | 39 | 41 |
| 40 | 42 | return self; | 41 | 43 | } | @@ -56,4 +58,20 @@ - (void)setBackgroundImage:(UIImage *)image forCellType:(RETableViewCellType)cel | 56 | 58 | [_backgroundImages setObject:image forKey:@(cellType)]; | 57 | 59 | } | 58 | 60 |
| | 61 | +- (BOOL)hasCustomSelectedBackgroundImage | | 62 | +{ | | 63 | + return [self selectedBackgroundImageForCellType:RETableViewCellFirst] || [self selectedBackgroundImageForCellType:RETableViewCellMiddle] || [self selectedBackgroundImageForCellType:RETableViewCellLast] || [self selectedBackgroundImageForCellType:RETableViewCellSingle]; | | 64 | +} | | 65 | + | | 66 | +- (UIImage *)selectedBackgroundImageForCellType:(RETableViewCellType)cellType | | 67 | +{ | | 68 | + return [_selectedBackgroundImages objectForKey:@(cellType)]; | | 69 | +} | | 70 | + | | 71 | +- (void)setSelectedBackgroundImage:(UIImage *)image forCellType:(RETableViewCellType)cellType | | 72 | +{ | | 73 | + if (image) | | 74 | + [_selectedBackgroundImages setObject:image forKey:@(cellType)]; | | 75 | +} | | 76 | + | 59 | 77 | @end |
|