我有以下方法在 RectFrame(宽度 = 170,高度 = 30)中绘制文本(文本为“0%”,字体大小 = 30):
/* Draw String IOS 7 up */
-(void) drawString: (CGRect) contextRect withStr: (NSString *) string {
NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
textStyle.lineBreakMode = NSLineBreakByWordWrapping;
textStyle.alignment = NSTextAlignmentCenter;
UIFont *font = [UIFont systemFontOfSize:_textSize];
UIColor* textColor = [UIColor grayColor];
NSDictionary* stringAttrs = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:textStyle, NSForegroundColorAttributeName:textColor};
[string drawInRect:contextRect withAttributes:stringAttrs];
}
我无法发布图像结果,但结果是文本在框架顶部下方绘制了一些像素,但底部很好(文本底部与底部框架匹配),无论我如何调整框架的大小和文字,它总是在框架顶部下方绘制“某处”,有什么想法吗?