gpt4 book ai didi

ios - UIbutton 图像更改为默认值

转载 作者:行者123 更新时间:2023-11-29 04:13:04 26 4
gpt4 key购买 nike

我有一个 Uibutton,它的默认背景图像已设置,我在运行时更改其图像,但我想保留所选图像。但每次我单击 uibutton 图像都会更改为默认值。这是代码

- (void)changeColorOnRuntTime:(UIColor *)color{

[btnTmpForColorPicker setBackgroundImage:[self imageNamed:@"customColor.png" withTint:color] forState:UIControlStateNormal];
[btnTmpForColorPicker setBackgroundImage:[self imageNamed:@"customColor.png" withTint:color] forState:UIControlStateHighlighted];

// [btnTmpForColorPicker seti];
// tmpColor = [UIColor alloc]ini;
tmpColor = [color copy];
// NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
// [defaults setValue:color forKey:@"CustomPreColor"];

[[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:color] forKey:@"CustomPreColor"];

}

和 btnHandler 中

if (popOverColorPicker.popoverVisible) {
[popOverColorPicker dismissPopoverAnimated:YES];
}
else
{
sdViewController = [[SDColorPickerViewController alloc]init];
sdViewController.color = [UIColor whiteColor];
sdViewController.tag = 1;
sdViewController.delegate = self;
// CGRect rect = CGRectMake(viewController.view.frame.origin.x, viewController.view.frame.origin.y, viewController.view.frame.size.width, 380);
// viewController.view.frame = rect;
btnTmpForColorPicker = (UIButton*)sender;
UIButton *senderbt = (UIButton*) sender;
if (tmpColor) {
[btnTmpForColorPicker setBackgroundImage:[self imageNamed:@"customColor.png" withTint:tmpColor] forState:UIControlStateNormal];
[btnTmpForColorPicker setBackgroundImage:[self imageNamed:@"customColor.png" withTint:tmpColor] forState:UIControlStateHighlighted];
}

// [popOverColorPicker setPopoverContentSize:CGSizeMake(viewController.view.frame.size.width, 380)];
popOverColorPicker = [[UIPopoverController alloc]initWithContentViewController:sdViewController];
[popOverColorPicker setPopoverContentSize:CGSizeMake(300, 390)];
[popOverColorPicker presentPopoverFromRect:senderbt.frame inView:self permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

最佳答案

替换这个:

[btnTmpForColorPicker setBackgroundImage:[self imageNamed:@"customColor.png" withTint:color] forState:UIControlStateHighlighted];

这样:

[btnTmpForColorPicker setBackgroundImage:[self imageNamed:@"customColor.png" withTint:color] forState:UIControlStateHighlighted] || UIControlStateSelected];

并对 btnHandler 按钮应用相同的更改

关于ios - UIbutton 图像更改为默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14102202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com