ios 绘制字符串
繪制字符串:
- (void)drawRect:(CGRect)rect {NSString *str = @"這是一段用于測試的文字這是一段用于測試的文字這是一段用于測試的文字這是一段用于測試的文字這是一段用于測試的文字這是一段用于測試的文字";NSMutableDictionary *dic = [NSMutableDictionary dictionary];dic[NSFontAttributeName] = [UIFont systemFontOfSize:18];dic[NSForegroundColorAttributeName] = [UIColor redColor];dic[NSBackgroundColorAttributeName] = [UIColor greenColor];//高度 給一個盡量大的值 ,該方法返回的frame中的高度,會根據(jù)寬度計(jì)算實(shí)際的高度,也就是說返回的矩形中的高度,是實(shí)際應(yīng)該使用的高度CGRect textFrame = [str boundingRectWithSize:CGSizeMake(200, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];NSLog(@"%@",NSStringFromCGRect(textFrame));CGFloat height = textFrame.size.height;//繪制矩形UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRect:CGRectMake(50, 50, 200, height)];//畫矩形[[UIColor yellowColor]setFill];[bezierPath fill];//繪制字符串[str drawInRect:CGRectMake(50, 50, 200, height) withAttributes:dic];//在矩形上畫字// [str drawAtPoint:CGPointMake(50, 50) withAttributes:dic]; }轉(zhuǎn)載于:https://www.cnblogs.com/xulinmei/p/7420281.html
新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎!定制產(chǎn)品紅包拿不停!總結(jié)
- 上一篇: 利用scons构建project
- 下一篇: Tornado 高并发源码分析之六---