【发布时间】:2014-05-14 09:43:51
【问题描述】:
我正在尝试创建一个 200 像素的圆角正方形,以用作 IOS 吐司样式指示。
到目前为止,我有以下 -
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1].CGColor);
CGContextMoveToPoint(context, 10, 0);
CGContextAddLineToPoint(context, 95, 0);
CGContextAddArcToPoint(context, 100, 0, 100, 5, 10);
CGContextAddLineToPoint(context, 100, 95);
CGContextAddArcToPoint(context, 100, 100, 95, 100, 10);
CGContextAddLineToPoint(context, 5, 100);
CGContextAddArcToPoint(context, 0, 100, 0, 95, 10);
CGContextAddLineToPoint(context, 0, 5);
CGContextAddArcToPoint(context, 0, 0, 5, 0, 10);
CGContextFillPath(context);
}
我是按照教程完成的——它绘制了一个完美的 100 像素圆角正方形——但我需要一个 150 像素的正方形!我已经改变了每一个可以想象的设置 - 有一些奇怪的结果 - 但无法弄清楚宽度高度是如何定义的!?谁能给点建议?
【问题讨论】:
-
150 还是 200?我不清楚
-
如果这就是您要查找的全部内容,请查看 Simon 的答案。该框架为您提供所需的一切。对于更复杂的表格,核心图形真的很有帮助。当您使用核心图形绘制自己的图形时,我建议使用变量(或常量开始),例如 with、height 和 conerRadius。首先,它更容易编程。但其次,它更灵活。然后,您只需将宽度和高度从 100 更改为 150 即可。
标签: ios objective-c cgcontext