Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 图形UIView与图形CGContext路径_Ios_Objective C_Performance_Uiview_Cgcontext - Fatal编程技术网

Ios 图形UIView与图形CGContext路径

Ios 图形UIView与图形CGContext路径,ios,objective-c,performance,uiview,cgcontext,Ios,Objective C,Performance,Uiview,Cgcontext,我想知道在使用 ui视图: UIView *box = [[UIView alloc] initWithFrame:CGRectMake(ax, ay, width, height)]; box.backgroundColor = [UIColor clearColor]; box.layer.borderColor = [UIColor whiteColor].CGColor; box.layer.borderWidth = lineWidth; [self.view addSubview:b

我想知道在使用
ui视图

UIView *box = [[UIView alloc] initWithFrame:CGRectMake(ax, ay, width, height)];
box.backgroundColor = [UIColor clearColor];
box.layer.borderColor = [UIColor whiteColor].CGColor;
box.layer.borderWidth = lineWidth;
[self.view addSubview:box];
CGContext

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, lineWidth);
CGContextSetStrokeColorWithColor(context, color.CGColor);
CGContextMoveToPoint(context, ax, ay);
CGContextAddLineToPoint(context, ax+width, ay);
CGContextAddLineToPoint(context, ax+width, ay+height);
CGContextAddLineToPoint(context, ax, ay+height);
CGContextAddLineToPoint(context, ax, ay);
CGContextStrokePath(context);

这完全取决于你想要实现什么。如果你画了很多矩形,你可能应该选择
CGContext
的方式。如果它只是一个围绕其他视图元素的矩形,那么最好使用UIView方法。
一般来说,我认为不鼓励使用UIViews在屏幕上绘制内容,因此当有疑问时,使用CGContext

这个问题的唯一答案应该是测量并查看对于您的确切用例来说什么是最有效的。