我现在感觉很傻。
我正在尝试将文本绘制到 UIViewController 上。
我正在使用 Xcode 5 并从一个简单的单页项目开始,除了将此代码添加到 ViewController.m 之外,我什么也没做:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGRect myRect=CGRectMake(0,0,self.view.bounds.size.width,self.view.bounds.size.height);
UIFont *myFont=[UIFont fontWithName:@"Helvetica" size:50];
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
paragraphStyle.alignment = NSTextAlignmentRight;
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
[attributes setObject:myFont forKey:NSFontAttributeName];
[attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
[attributes setObject:[NSNumber numberWithFloat:4] forKey:NSStrokeWidthAttributeName];
[attributes setObject:[UIColor whiteColor] forKey:NSStrokeColorAttributeName];
[@"test" drawInRect:myRect withAttributes:attributes];
// draw fill
[attributes removeObjectForKey:NSStrokeWidthAttributeName];
[attributes removeObjectForKey:NSStrokeColorAttributeName];
[attributes setObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName];
[@"test" drawInRect:myRect withAttributes:attributes];
}
它运行没有错误,但不产生任何文本 - 为什么?