【发布时间】:2023-03-11 23:35:02
【问题描述】:
对于我的应用,我需要实现一个绘图空间。在在线教程的帮助下,我成功绘图。但现在的挑战是用不同的颜色来绘制。我在下面编写了代码,但它不起作用,我不明白为什么它不起作用。它只涂成黑色。 我的 UIView.m 中有以下内容
- (void)drawBitmap
{
UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0.0);
if (!incrementalImage) // first time; paint background white
{
UIBezierPath *rectpath = [UIBezierPath bezierPathWithRect:self.bounds];
[[UIColor whiteColor] setFill];
[rectpath fill];
}
[incrementalImage drawAtPoint:CGPointZero];
[color setStroke];
[path stroke];
incrementalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
- (void)color1 {
color = [UIColor greenColor];
}
- (void)color2 {
color = [UIColor yellowColor];
}
我从 ViewController.m 调用函数
- (IBAction)drawGreen:(id)sender {
SmoothedBIView *smoothView = [[SmoothedBIView alloc]init];
[smoothView color1];
}
- (IBAction)drawYellow:(id)sender {
SmoothedBIView *smoothView = [[SmoothedBIView alloc] init];
[smoothView color2];
}
感谢您的帮助!
【问题讨论】:
-
“它不起作用”是什么意思?预期结果是什么,实际结果是什么?
-
颜色只是黑色,不会变成另一种颜色。
-
你还没有展示你的函数 color1 和 color2 是如何被调用的。
-
你的问题一清二楚。代码
[color setStroke]中的“颜色”是什么?为什么你们都将增量图像绘制到上下文中,然后将其作为绘图的输出获取?
标签: ios objective-c xcode colors draw