Keeps original background color of a subview in during row selection

When a row is selected in UITableView, background colors of all UIView subviews gets changed. This class will prevent that from happening so that the blue dot can remain blue while the row is selected. Description and solution suggestions found in the following link:
https://stackoverflow.com/questions/6745919/uitableviewcell-subview-disappears-when-cell-is-selected/27717607
pull/1/head
Fredrik Lillejordet 7 years ago committed by Matthew Chen
parent f9fc882864
commit 8984f659f3

@ -106,7 +106,7 @@ const NSUInteger kAvatarViewDiameter = 52;
[self.timeLabel setCompressionResistanceHigh];
const int kunreadBadgeSize = 24;
self.unreadBadge = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kunreadBadgeSize, kunreadBadgeSize)];
self.unreadBadge = [[NeverClearUIView alloc] initWithFrame:CGRectMake(0, 0, kunreadBadgeSize, kunreadBadgeSize)];
self.unreadBadge.layer.cornerRadius = kunreadBadgeSize / 2;
self.unreadBadge.backgroundColor = [UIColor ows_materialBlueColor];
[self.contentView addSubview:self.unreadBadge];

@ -0,0 +1,12 @@
// Created by Fredrik Lillejordet on 04.03.2018.
// Copyright © 2018 Open Whisper Systems. All rights reserved.
@objc class NeverClearUIView: UIView {
override var backgroundColor: UIColor? {
didSet {
if backgroundColor != nil && backgroundColor!.cgColor.alpha == 0 {
backgroundColor = oldValue
}
}
}
}
Loading…
Cancel
Save