Quartz2D-1(画文字、图片)

本文介绍了如何在iOS应用中使用Objective-C绘制指定的文字和图片。通过设置上下文和属性,实现了文字的显示及图片的不同绘制方式,如平铺、拉伸及指定位置绘制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/**

 *  画文字

 *

 *  @param rect <#rect description#>

 */

- (void)drawRect:(CGRect)rect {

    NSString *text = @"房价阿里价格的感觉啊;栏杆机;第三个哭敬爱个;惊呆了噶舒服发的撒个";

    CGRect rt = CGRectMake(50.0,0.0, 100, 100);

    // 获取上下文

    CGContextRef ctf = UIGraphicsGetCurrentContext();

    // 绘图

    CGContextAddRect(ctf, rt);

    // 渲染

    CGContextStrokePath(ctf);

    

    NSMutableDictionary *dict = [NSMutableDictionary dictionary];

    [dict setValue:[UIColor greenColor] forKey:NSForegroundColorAttributeName];

    //dict[NSForegroundColorAttributeName] = [UIColor redColor];

    dict[NSBackgroundColorAttributeName] = [UIColor whiteColor];

    dict[NSFontAttributeName] = [UIFont systemFontOfSize:14];

    

    // ios7.0

    [text drawInRect:rt withAttributes:dict];

}



/**

 *  画图片

 *

 *  @param rect <#rect description#>

 */

- (void)drawRect:(CGRect)rect

{

    UIImage *image = [UIImageimageNamed:@"92AE1EE8-0B99-4F28-8B81-66B18E9A0001"];

//    [image drawAsPatternInRect:rect]; //平铺,大小不变

//    [image drawInRect:rect];// 拉伸图片

    [image drawAtPoint:CGPointMake(10,20)]; // 从一个点画,大小不变

}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值