首先写个UIImage的类别 为的就是要点击效果。PS:直接 [self.rightBtn setBackgroundColor:color]是没有点击高亮效果的。
@implementation UIImage (colorful)
+ (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end
然后
[self.rightBtn setBackgroundImage:[UIImage imageWithColor:[UIColor color]] forState:UIControlStateNormal];就有点击高亮的效果了