首页 > CGContextRef 画不出直线

CGContextRef 画不出直线

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

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

继承UIView,重写方法

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();    
    CGContextMoveToPoint(context, 20, 20);
    CGContextAddLineToPoint(context, 100,100);
    CGContextStrokePath(context);
}
【热门文章】
【热门文章】