也许大家项目中会用到UICollectionViewCell选中后给一个背景色,然后我今天就遇到了
很幸运的是,在网上很快搜到了 selectedBackgroundView 这个属性 ,合理运用,下面是代码,简单的一个View
#import "RoleCollectionViewCell.h"
@implementation RoleCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self creatViews];
self.layer.borderWidth = 0.5;
self.layer.borderColor = YYColor(226, 226, 226).CGColor;
}
return self;
}
- (void)creatViews {
UIView *backgroundView = [UIView new];
backgroundView.backgroundColor = YYColor(250, 239, 218);
self.selectedBackgroundView = backgroundView;