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中的高度,會根據寬度計算實際的高度,也就是說返回的矩形中的高度,是實際應該使用的高度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]; }轉載于:https://www.cnblogs.com/xulinmei/p/7420281.html
新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!總結
- 上一篇: 利用scons构建project
- 下一篇: Tornado 高并发源码分析之六---