我想将 UIColor * 作为参数传递,但我的程序在 [paramColour set] 处不断崩溃。我知道我可以传入一个字符串并从那里选择 UIColor 但我只是想知道为什么这不起作用。帮助将不胜感激。
- (void) drawRooftopAtTopPointof:(CGPoint)paramTopPoint
colour:(UIColor *)paramColour
lineJoin:(CGLineJoin)paramLineJoin{
/* Set the color that we want to use to draw the line */
[paramColour set];
/* Get the current graphics context */
CGContextRef currentContext = UIGraphicsGetCurrentContext();
/* Set the line join */
CGContextSetLineJoin(currentContext,
paramLineJoin);
/* Set the width for the lines */
CGContextSetLineWidth(currentContext,
3.0f);
/* Start the line at this point */
CGContextMoveToPoint(currentContext,
paramTopPoint.x - 10,
paramTopPoint.y + 8);
/* And end it at this point */
CGContextAddLineToPoint(currentContext,
paramTopPoint.x,
paramTopPoint.y);
/* Extend the line to another point to
make the rooftop */
CGContextAddLineToPoint(currentContext,
paramTopPoint.x + 10,
paramTopPoint.y + 8);
/* Use the context's current color to draw the lines */
CGContextStrokePath(currentContext);
/* Draw the text in the rooftop using a black color */
[[UIColor blackColor] set];
}
这是触发此绘图功能的视图中的drawRect。
- (void)drawRect:(CGRect)rect
{
for (int i=0; i < arrowsToDrawArray.count; i++)
{
Arrow * arrowObj = [arrowsToDrawArray objectAtIndex:i];
UIColor * colourOfArrow = [arrowObj colourOfArrow]; // colour determines whether right or wrong
CGPoint p = [arrowObj arrowPlacement];
// CGPoint p = [val CGPointValue];
[self drawRooftopAtTopPointof:p colour:colourOfArrow lineJoin:kCGLineJoinMiter];
}
}
这是箭头类的定义。
#import <UIKit/UIKit.h>
@class Arrow;
@interface Arrow : NSObject
{
UIColor * colourOfArrow;
CGPoint arrowPlacement;
}
@property (nonatomic,retain) UIColor * colourOfArrow;
@property (nonatomic) CGPoint arrowPlacement;
@end