如何创建纯色的UIImage或者UIImageView
1个回答
展开全部
方法如下:
+ (UIImage *) imageWithColor: (NSString *)color widthButton:(UIButton *)button
{
CGSize imageSize = CGSizeMake(button.frame.size.width, button.frame.size.height);
UIGraphicsBeginImageContextWithOptions(imageSize, NO, [UIScreenmainScreen].scale);
[[mmsUT_UICommon colorWithHexString:color] set];
UIRectFill(CGRectMake(0, 0, imageSize.width, imageSize.height));
UIImage *pressedColorImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return pressedColorImg;
}
+ (UIImage *) imageWithColor: (NSString *)color widthButton:(UIButton *)button
{
CGSize imageSize = CGSizeMake(button.frame.size.width, button.frame.size.height);
UIGraphicsBeginImageContextWithOptions(imageSize, NO, [UIScreenmainScreen].scale);
[[mmsUT_UICommon colorWithHexString:color] set];
UIRectFill(CGRectMake(0, 0, imageSize.width, imageSize.height));
UIImage *pressedColorImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return pressedColorImg;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询