我正在使用drawInRect:withAttributes在iOS 7中向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];