I have an app with a button in the bottom that i’m creating using a UIButton library, GradientButton (found here: http://code.google.com/p/iphonegradientbuttons/).
I can create buttons fine, but i cannot for the world figure out how to change the colour gradient of the created button after i’ve set the color once…
I tried, as an example, to change the gradient in my button’s actionlistener with various tricks, for example (i’m setting it in viewdidload the first time):
- (IBAction)buttonPressed:(id)sender{
NSLog(@"buttonPressed;changing style");
[checkInCheckOutButton useAlertStyle];//build-in method in gradientbutton that sets colour
[checkInCheckOutButton setNeedsDisplay];//added this when first didn't work.
}
Am i missing something here? If i change any other, built-in component, say a regular button’s text and/or background, all works fine.
If there’s something i’m not getting regarding how objects are repainted in objective c, i’m all ears…
EDIT: after suggestion, i tried to add some code to alter the color arrays of the button. Unfortunately that didn’t work either:
- (IBAction)buttonPressed:(id)sender{
NSLog(@"buttonPressed;changing style");
self.checkInCheckOutButton.normalGradientColors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor blueColor], nil];
self.checkInCheckOutButton.highlightGradientColors = [NSArray arrayWithObjects:[UIColor greenColor], [UIColor whiteColor], nil];
[self.checkInCheckOutButton setNeedsDisplay];//tried with and without
I found a solution. Add these lines to the begin of every
use...Stylemethod:and add
[self setNeedsDisplay];at the end of these methods.After these changes it works!