我如何在self.view中调用此方法?

2 iphone objective-c drawrect ios

我正在制作这种绘制线的方法现在我想要的是用另一种方法调用它我该怎么做,请帮我解决这个问题,如何在self.view中添加它?

- (void)drawRect:(CGRect)rect
{
     CGContextRef context = UIGraphicsGetCurrentContext();

     CGContextSetLineWidth(context, 5.0);

     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

     CGFloat dashArray[] = {2,6,4,2};

     CGContextSetLineDash(context, 3, dashArray, 4);

     CGContextMoveToPoint(context, 10, 200);

     CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200);

     CGContextStrokePath(context);

 }
Run Code Online (Sandbox Code Playgroud)

tro*_*foe 8

将视图标记为需要重绘:

[self.view setNeedsDisplay];
Run Code Online (Sandbox Code Playgroud)

参考文献.


Bhu*_*esh 5

 [self.view setNeedsDisplay];
Run Code Online (Sandbox Code Playgroud)

这将调用draw rect方法.