清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 200, 400, 500)];
UIGraphicsBeginImageContext(imageView1.frame.size); //开始画线
[imageView1.image drawInRect:CGRectMake(0, 0, imageView1.frame.size.width, imageView1.frame.size.height)];
//设置上下文
CGContextRef context = UIGraphicsGetCurrentContext();
//边框大小
CGContextSetLineWidth(context, 1);
//边框颜色
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
//矩形填充颜色
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
/*
大概解释一下
从(180,280-70)到(180,280)画一条线,然后再从(180,280)到( 180-20, 280)画一条线,从这两条线(无限延伸的) 和半径10可以确定一条弧
说的是下面前两行的意思 下面依次类推
*/
CGContextMoveToPoint(context, 180, 280-70); // 开始坐标右边开始
CGContextAddArcToPoint(context, 180, 280, 180-20, 280, 10); // 右下角角度
CGContextAddArcToPoint(context, 120, 280, 120, 280-10, 10); // 左下角角度
CGContextAddArcToPoint(context, 120, 200, 180-20, 200, 10); // 左上角
CGContextAddArcToPoint(context, 180, 200, 180, 280-70, 10); // 右上角
CGContextDrawPath(context, kCGPathFillStroke); //根据坐标绘制路径
imageView1.image = UIGraphicsGetImageFromCurrentImageContext();//获取绘图
[self.view addSubview:imageView1];
}