【发布时间】:2014-08-09 10:19:42
【问题描述】:
我有下面的方法在 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];
}
我无法发布图像结果,但结果是文本在框架顶部下方绘制了一些像素但底部很好(文本底部与底部框架匹配),无论我如何调整框架和文本的大小,它总是画在框架顶部下方的“某处”,有什么想法吗?
【问题讨论】:
标签: ios objective-c nsstring alignment drawinrect