Tag: uiview uibezierpath

在代码生成的UIView上绘制UIBezierPath

我在运行时在代码中添加了UIView 。 我想绘制一个UIBezierPath ,但是这意味着我不得不重写drawRect for UIView? 或者是有另一种方式来绘制到自定义的UIView ? 这里是生成UIView的代码: UIView* shapeView = [[UIView alloc]initWithFrame:CGRectMake(xOrigin,yOrigin+(i*MENU_BLOCK_FRAME_HEIGHT), self.shapeScroll.frame.size.width, MENU_BLOCK_FRAME_HEIGHT)]; shapeView.clipsToBounds = YES; 这里是创build和返回一个UIBezierPath的函数: – (UIBezierPath*)createPath { UIBezierPath* path = [[UIBezierPath alloc]init]; [path moveToPoint:CGPointMake(100.0, 50.0)]; [path addLineToPoint:CGPointMake(200.0,50.0)]; [path addLineToPoint:CGPointMake(200.0, 200.0)]; [path addLineToPoint:CGPointMake(100.0, 200.0)]; [path closePath]; return path; }