在我的签名 View 中,我想提供更改 Ibaction 颜色的选项。例如,如果用户单击红色按钮,则绘图颜色应该是红色,就像这样,我尝试了教程http://www.edumobile.org/iphone/iphone-beginner-tutorials/digital-signature-application-in-iphone/ ,这里是着色代码
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
我的疑问是如何将其作为单独的按钮方法,并在单击时执行颜色?
最佳答案
嗨,只需将值作为变量即可
如果您在 drawrect 方法中编写此代码
您可以通过[self setNeedsDisplay];
更新
- (void)drawRect:(CGRect)rect
{
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), redValue, greenValue, blueValue, alpha);
}
-(IBAction)updateColor{
redValue = red color code;
greenValue = green color code;
blueValue = blue color code;
alphaValue = alpha value;
[self setNeedsDisplay];
}
关于iphone - 单击按钮时颜色变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13392468/