【问题标题】:Drawing UIView vs Drawing CGContext Path绘制 UIView 与绘制 CGContext 路径
【发布时间】:2014-04-15 13:58:46
【问题描述】:

我想知道在使用 UIView

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);

【问题讨论】:

  • 这个问题的唯一答案应该是衡量,看看什么对您的确切用例最有效。

标签: ios objective-c performance uiview cgcontext


【解决方案1】:

这完全取决于您想要实现的目标。如果您要绘制很多矩形,您可能应该采用CGContext 方式。如果它只是一些其他视图元素周围的矩形,则最好使用 UIView 方法。 一般来说,我认为不鼓励使用 UIViews 在屏幕上绘制东西,所以当有疑问时使用 CGContext

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 2015-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多