NSDate *now = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy"];
NSString *stringFromDate = [formatter stringFromDate:now];
CGContextShowTextAtPoint(context, 50, 50, stringFromDate, 5);
我没有得到确切的日期?编译时也收到警告
警告:从不兼容的指针类型传递“CGContextShowTextAtPoint”的参数 4
最佳答案
stringFromDate
的值是多少?你在期待什么?
如果您查看 CGContextShowTextAtPoint
的文档,您会发现第四个参数需要是 char*
,而不是 NSString*.
你有:
GContextShowTextAtPoint(context, 50, 50, stringFromDate, 5);
你要:
GContextShowTextAtPoint(context, 50, 50, [stringFromDate UTF8String], 5);
关于objective-c - 将 NSString 转换为字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2926726/