【发布时间】:2016-11-11 20:12:20
【问题描述】:
这真的很简单,但我无法弄清楚我做错了什么。
我有一个视图控制器,中间有一个视图。我想画下面的圆圈:
我遇到的主要问题是我无法在视图中显示任何内容。我现在只是想画一条线,但显然缺少一些关键。这是我的代码:
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *centerView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[[UIColor brownColor] set];
CGContextRef currentContext =UIGraphicsGetCurrentContext();
CGContextSetLineWidth(currentContext,5.0f);
CGContextMoveToPoint(currentContext,50.0f, 10.0f);
CGContextAddLineToPoint(currentContext,100.0f, 200.0f);
CGContextStrokePath(currentContext);
}
【问题讨论】:
-
这里缺少很多基础知识。从Drawing and Printing Guide for iOS 开始,也许吧?
-
我喜欢 drawRect 中的 UIBezierPath:
-
你应该通过子类化
UIView来尝试整个事情,并将你的绘图代码放在drawRect中 -
感谢@RatulSharker。这就是我所缺少的!
标签: ios objective-c iphone core-graphics