iOS Quartz2D - 画文字 和 图片

本文将为您介绍如何使用Objective-C在iOS应用中绘制文字和图片的基本方法,包括文字属性设置、图片绘制位置与大小调整等核心内容。
/**
 *  画文字
 */
- (void)drawRect:(CGRect)rect {
   
    //1.获得图形上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
   //2.画文字
    NSString *str = @"哈哈哈哈";
    [str drawAtPoint:CGPointZero withAttributes:nil];
    
    //文字属性字典
    NSMutableDictionary *atts = [NSMutableDictionary dictionary];
    atts[NSForegroundColorAttributeName] = [UIColor redColor];
    atts[NSFontAttributeName] = [UIFont systemFontOfSize:20];
                                 
    [str drawInRect:CGRectMake(50, 50, 100, 100) withAttributes:atts];
    
    //3.渲染显示到view上
    CGContextStrokePath(ctx);

}
/**
 *  画图片
 */
- (void)drawRect:(CGRect)rect {
   
   //1.取得图片
    UIImage *image = [UIImage imageNamed:@"me"];
    
    //2.画
    [image drawAtPoint:CGPointMake(50, 50)];
    [image drawInRect:CGRectMake(0, 0, 150, 150)];
    [image drawAsPatternInRect:CGRectMake(0, 0, 200, 200)]; //平铺图片
}


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值