ios - UITableView cell selection -
I have got a UILB in the cell with the background color when I select this cell, the cell color changes (Which should do it), but it also changes the background of the label. I want to preserve the background color on UILabel when I use an image only in a random color, it is preserved, but is there no better way?
Thanks in advance
code:
_label = [UILabel new]; _label.translatesAutoresizingMaskIntoConstraints = No; _label.font = [UIFont systemFontOfSize: 10.f]; _label.backgroundColor = HEXCOLOR (0xFFE5E5E5); // macro just a UIColor but I can add a different selection color like this (with something to do)
UIView * selectionColor = [[UIView alloc] init]; Selectioncolor.backgroundColor = HEXCOLOR (0XFFF1F1F1); Self.selectedBackgroundView = selectionColor; Self.contentView.backgroundColor = [UIColor whiteColor]; Nothing really for this
Solution: Create sub-classes of UILB and do not just call super
- ( Instancetype) initWithColor: (UIColor *) color {self = [super init]; If (self) {[super setback color: color]; } Healthy return; } - (zero) setBackgroundColor: (UIColor *) background_roller {// do nothing here! } The default behavior of
UITableView is that when someone The cell is chosen as the background color of the subvues of all cells, temporarily removed.
We usually control this problem with UILabel sub-closing, set setBackgroundColor: and simply [super setBackgroundColor:] Do not call after setting your color @interface MyLabel: UILabel @property (nonatomic) BOOL BackgroundRock; @end @implementation MyLabel - (zero) setbackgram color: (UIColor *) background_roll {if (_backgroundColorLocked) {return; } Super.backgroundColor = backgroundColor; } @end
Usage:
MyLabel * label = â ?? | | Label.backgroundColor = UIColor.redColor; Label.backgroundColorLocked = YES; Unless backgroundColorLocked is yes none, even UITableView (cell) Change the background color of the label can.
Comments
Post a Comment