好久沒(méi)用了。
CGSize imageSize = CGSizeMake(50, 50);
UIGraphicsBeginImageContextWithOptions(imageSize, 0, [UIScreen mainScreen].scale);
[[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1] set];
UIRectFill(CGRectMake(0, 0, imageSize.width, imageSize.height));
UIImage *pressedColorImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[btn setBackgroundImage:pressedColorImg forState:UIControlStateHighlighted];
無(wú)需添加純色圖片文件,為button設(shè)置高亮背景,Do it like this . 媽媽再也不用擔(dān)心了。