我递了(NSInteger) pageIndex
,需要在
void CGContextShowTextAtPoint (
CGContextRef c,
CGFloat x,
CGFloat y,
const char *string,
size_t length
);
如何获取const char *string
而不忘记该字符串的长度
我倾向于最终使用令人讨厌的技巧将整数转换为字符串,然后执行cStringUsingEncoding:NSMacOSRomanStringEncoding
但这不是最优雅的方式
为了完整性,这是代码
const char *pageIndexString = [[NSString stringWithFormat:@"%d", pageIndex] cStringUsingEncoding:NSMacOSRomanStringEncoding];
CGContextShowTextAtPoint(CGContextRef, CGFloat x, CGFloat y, pageIndexString, strlen(pageIndexString));
答案 0 :(得分:3)
试试这个:
NSString *tmp = [NSString stringWithFormat:@"%ld", pageIndex];
const char *str = [tmp UTF8String];
size_t length = [tmp length];