问题描述
- iOS开发时,如何在图片上旋转一个角度绘制文字,例如在点(50,80)处,旋转50°画文字
-
要求不用到 label
现在需要在apple mapkit 中自定义的annotation图片上绘制编号,此图片是个箭头,
可旋转方向。为了让箭头旋转时其上的文字始终竖直。现需要在image上画出旋转一定角度的文字,或者用上下文画一个旋转一定角度的图片也可以,求大神指点
解决方案
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = NSLineBreakByClipping;
paragraphStyle.alignment = NSTextAlignmentCenter;
NSDictionary *attributes =@{NSFontAttributeName:[UIFont systemFontOfSize:17],
NSForegroundColorAttributeName:whiteColor,
NSParagraphStyleAttributeName:paragraphStyle};
CGFloat startX = (_clockSize.width-95)/2;
CGFloat startY = _clockSize.height+10;
CGFloat width = 25;
CGFloat height = 25;
CGFloat space = 10;
CGRect hourRect = CGRectMake(startX, startY, width, height);
UIBezierPath* hourPath = [UIBezierPath bezierPathWithRect:hourRect];
[KMainItemColor setFill];
[hourPath fill];
[whiteColor setFill];
NSAttributedString *hourAttri = [[NSAttributedString alloc] initWithString:hour
attributes:attributes];
[hourAttri drawAtPoint:CGPointMake(CGRectGetMidX(hourRect)-hourAttri.size.width/2, CGRectGetMidY(hourRect)-hourAttri.size.height/2)];
时间: 2024-08-29 11:21:22