开发者

Change color of button based on user input (button press)

I need to change the images/colors (whichever is easier) of buttons in a view different from the one the button is located. Any ideas? This is for iOS and I have been trying for days to get this to wor开发者_高级运维k. Thanks!


I don't know if this is the proper way to do this (kinda depends on the context), but you could you us user defaults:

 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    NSString *fooButtonColor = @"red";
    [prefs setObject:fooButtonColor forKey:@"fooButtonColor"];

You would put this code in the .m file of the class where you want to "set" the color. In

Then in the other view, get the color from the defaults and check e.g. by doing a string comparison:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:fooButtonColor forKey:@"fooButtonColor"];
NSString *fooButtonColor = [prefs objectForkey:@"fooButtonColor"];
if ([fooButtonColor isEqualtoString @"red"]) {
foobutton.backgroundColor = [UIColor redColor];
}

Probably more efficient would be to use rgba values. Check out this question: Saving UIColor to and loading from NSUserDefaults

Good luck

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜