【发布时间】:2014-02-22 06:16:08
【问题描述】:
我在 iOS 7 中使用 drawInRect : withAttributes 向 pdf 添加文本。我需要将 CGRect 内的文本垂直居中,或者至少我需要在 CGRect 边框和文本之间保持一些间隙/填充。否则文本看起来太靠近框。有什么属性可以做到这一点吗?如果不是,最好的方法是什么?下面是我的代码。
我试过 NSBaselineOffsetAttributeName ,但它只会增加每条线之间的间隙,但不会增加到矩形边界的间隙。
谢谢
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(currentContext, bgColor.CGColor);
CGRect renderingRect = CGRectMake(startPoint.x, startPoint.y, width, height);
CGContextFillRect(currentContext, renderingRect);
NSDictionary *attributes = @{ NSFontAttributeName: font,
NSForegroundColorAttributeName: fgColor,
};
[textToDraw drawInRect:renderingRect withAttributes:attributes];
【问题讨论】:
标签: ios objective-c ios6 ios7 uikit