画图

    UIGraphicsBeginImageContext(self.view.bounds.size);
    //画矩形
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(20, 30, 200, 200)];
    //画圆
    path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 30, 200, 200) cornerRadius:100];
    path.lineWidth = 20;
    //填充色
    [[UIColor cyanColor] setFill];
    //线宽颜色
    [[UIColor redColor] setStroke];
    [path stroke];
    [path fill];
    
    UIImage *img = [UIImage imageNamed:@"1.png"];
    [img drawInRect:self.view.bounds];
    [@"AV女优精彩视频" drawInRect:CGRectMake(150, 500, 400, 200) withAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor], NSFontAttributeName:[UIFont systemFontOfSize:25]}];
    //画线
    UIBezierPath *linePath = [UIBezierPath bezierPath];
    [linePath moveToPoint:CGPointMake(100, 100)];
    [linePath addLineToPoint:CGPointMake(100, 300)];
    linePath.lineWidth = 10;
    [[UIColor greenColor] setStroke];
    [linePath stroke];
    //获取当前图形上下文图片
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    NSString *imagePath = @"Users/apple/Desktop/image.jpg";
    //将image转换成data数据
    NSData *data = UIImageJPEGRepresentation(image, 1);
    [data writeToFile:imagePath atomically:YES];
    //将图片画到屏幕
    self.view.layer.contents = (__bridge id)image.CGImage;
    UIGraphicsEndImageContext();

你可能感兴趣的:(画图)