[英]How do i make my GradientButton redraw in my iPhone app?
我有一个应用程序,该应用程序的底部有一个按钮,该按钮是使用UIButton库GradientButton(在此处找到: http : //code.google.com/p/iphonegradientbuttons/ )创建的。
我可以很好地创建按钮,但是我无法为世界确定在设置颜色一次后如何更改所创建按钮的颜色渐变...
例如,我尝试使用各种技巧来更改按钮的动作监听器中的渐变(例如,我是在第一次将其设置在viewdidload中):
- (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.
}
我在这里想念什么吗? 如果我更改任何其他内置组件,例如常规按钮的文本和/或背景,则一切正常。
如果关于物镜如何在目标c中重绘我没有得到什么,我会非常高兴...
编辑:建议后,我试图添加一些代码来更改按钮的颜色数组。 不幸的是,这也不起作用:
- (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
我找到了解决方案。 将这些行添加到每次use...Style
方法的开头:
normalGradient = NULL;
highlightGradient = NULL;
并添加[self setNeedsDisplay];
在这些方法的末尾。
这些更改后,它就可以工作了!
取决于何时/为什么要更改它。
它看起来像你可以只使用normalGradientColors
和highlightedGradientColors
以彻底改变颜色。
诚实地看起来,这就是您要做的所有事情。 只需更改这些属性即可。
//This changes the colors for UIControlStateNormal
theButton.normalGradientColors = [NSArray arrayWithObjects:(id)[[UIColor redColor] CGColor], (id)[[UIColor blueColor] CGColor], nil];
//This changes the colors for UIControlStateHighlighted
theButton.HighlightedGradientColors = [NSArray arrayWithObjects:(id)[[UIColor redColor] CGColor], (id)[[UIColor blueColor] CGColor], nil];
编辑:将演员表添加到CGColor。 如果您使用的是ARC,则必须添加网桥标记,而不是“简单”强制转换
(__bridge id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.