
如何让UIButton不可用变灰
1个回答
展开全部
Button.alpha = 0.4;
Button.enabled = NO;好了就是这样滴。
setadjustsImageWhenHighlighted = NO;也可以
或者
[saveBtn setBackgroundImage:[self imageWithColor:[UIColor grayColor]] forState:UIControlStateDisabled];
[saveBtn setBackgroundImage:[self imageWithColor:[UIColor colorWithHexString:@"#20BEFD"]] forState:UIControlStateNormal];
//颜色转换 背景图片
- (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;
}
Button.enabled = NO;好了就是这样滴。
setadjustsImageWhenHighlighted = NO;也可以
或者
[saveBtn setBackgroundImage:[self imageWithColor:[UIColor grayColor]] forState:UIControlStateDisabled];
[saveBtn setBackgroundImage:[self imageWithColor:[UIColor colorWithHexString:@"#20BEFD"]] forState:UIControlStateNormal];
//颜色转换 背景图片
- (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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询