iOS开发中常用的几种绘图方法

    

1. 矩形 UIBezierPath *path1 = [UIBezierPath bezierPathWithRect:CGRectMake(50, 50, 200, 100)];

 2. 圆角矩形   UIBezierPath *path2 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(50, 50, 200, 100) cornerRadius:20];
 3. 椭圆   UIBezierPath *path3 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 180, 200, 100)];
 4. 圆弧   UIBezierPath *path4 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(160, 160) radius:100 startAngle:M_PI_2*3 endAngle:0 clockwise:YES];
    [path5 addArcWithCenter:CGPointMake(160, 160) radius:100 startAngle:M_PI_2*3 endAngle:0 clockwise:YES];

4. 直线   UIBezierPath *path = [UIBezierPath bezierPath];   

  [path moveToPoint:CGPointMake(40, 40)];  

[path addLineToPoint:CGPointMake(40, 140)];   

[path addLineToPoint:CGPointMake(140, 140)];    

 path.lineWidth = 20;   

 path.lineCapStyle = kCGLineCapSquare;   

 path.lineJoinStyle = kCGLineJoinBevel;  

 [[UIColor greenColor] setFill];   

 [[UIColor redColor]setStroke];    

 [path stroke];  

 [path fill];

5. 绘制字符串 

    NSString *str = @"这是一段文字";
    NSDictionary *attributes = @{
        NSFontAttributeName:[UIFont systemFontOfSize:20],
        NSForegroundColorAttributeName:[UIColor redColor]};
    [str drawAtPoint:CGPointMake(30, 30) withAttributes:attributes];
[str drawInRect:CGRectMake(30, 30, 150, 200) withAttributes:attributes];
    CGRect textFrame =  [str boundingRectWithSize:CGSizeMake(200, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil];
    [str drawInRect:CGRectMake(50, 50, textFrame.size.width, textFrame.size.height) withAttributes:attributes];

6. 绘制图片

UIImage *image = [UIImage imageNamed:@"qie"];

     [image drawAtPoint:CGPointMake(50, 50)];

  [image drawInRect:CGRectMake(50, 90, 250, 250)];

NSString *str = @"张三";
    CGSize textSize = [str boundingRectWithSize:CGSizeMake(200, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17],NSForegroundColorAttributeName:[UIColor redColor]} context:nil].size;
  
    [str drawInRect:CGRectMake(300-textSize.width, 340-textSize.height, textSize.width, textSize.height) withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17],NSForegroundColorAttributeName:[UIColor redColor]}];



 
   

 
 
 
    


    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值