开发者社区 问答 正文

CGContextRef 画不出直线

为什么我用下面的代码就画不出直线呢,屏幕一片空白

- (void)viewDidLoad
{
    [super viewDidLoad];
    CGContextRef context = UIGraphicsGetCurrentContext();    
    CGContextMoveToPoint(context, 20, 20);
    CGContextAddLineToPoint(context, 100,100);
    CGContextStrokePath(context);
}

展开
收起
a123456678 2016-07-20 15:16:11 1825 分享 版权
1 条回答
写回答
取消 提交回答
  • 继承UIView,重写方法

    - (void)drawRect:(CGRect)rect
    {
        CGContextRef context = UIGraphicsGetCurrentContext();    
        CGContextMoveToPoint(context, 20, 20);
        CGContextAddLineToPoint(context, 100,100);
        CGContextStrokePath(context);
    }
    2019-07-17 19:58:55
    赞同 展开评论
问答地址: