在工作中遇到自定义cell点击效果的需求,系统的grayType色值与UI给的不一致。可以采用下面的方法实现。
1:在自定义的UITableViewCell的 -(void)aweakFromNib{}的方法中加入。
- (void)awakeFromNib {
[super awakeFromNib];
CGRect rect = CGRectMake(0, 0, self.width, self.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
//高亮颜色值
UIColor *selectedColor = [UIColor redColor];
CGContextSetFillColorWithColor(context, [selectedColor CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.selectedBackgroundView = [[UIImageView alloc] initWithImage:image];
}