- 翻转坐标系因为UIKit的坐标系和CGContext所在的坐标系不同 UIKit下面圆点在左上角 而CGContext所在的坐标系在左下角
未解决的时候
CGContextDrawImage(context, CGRectMake(50, 0, 100, 30), [UIImage imageNamed:@"douyu1"].CGImage);
drawImage.png
方法1:
颠倒坐标系
这样如果你想坐标是 100 10 你该改成坐标 100 (rect.size.height-imageHeight-10)
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, 0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, CGRectMake(50, rect.size.height - 30, 100, 30), [UIImage imageNamed:@"douyu1"].CGImage);
方法二:
使用方法
不需要关心坐标系相关的转换系统帮你做了
- (void)drawInRect:(CGRect)rect