NSString的阴影效果

时间:2012-08-24 13:47:11

标签: iphone ios ipad nsstring shadow

我想将阴影效果应用于NSString类型的文本。 虽然我了解如何将阴影效果应用于UILabel和其他视图元素, 我无法找到一种向文本添加阴影效果的方法。

我目前正在绘制文字如下:

NSString *text = @"Hello";
[text drawAtPoint:point width withFont:font minFontSize:22.0f actualFontSize:&actualFontSize lineBreakMode:UILineBreakModeTailTruncation baselineAdjustment:UIBaselineAdjustmentAlignBaselines];

我真的很感激任何帮助。谢谢!

1 个答案:

答案 0 :(得分:2)

尝试CGContextSetShadow()将阴影添加到文字

- (void)drawRect:(CGRect)rect 
{
NSString *string = @"Hello World!";

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShadow(context, CGSizeMake(20.0f, 20.0f), 10.0f);

[string drawAtPoint:CGPointMake(100.0f, 100.0f) withFont:[UIFont boldSystemFontOfSize:36.0f]];
}
相关问题