【发布时间】:2010-10-16 07:27:36
【问题描述】:
如何在 UIImage 视图上显示字符串?
好的,我现在知道了:
- (void)viewDidLoad {
[super viewDidLoad];
playerPositions = [[NSArray alloc] initWithObjects:box1,box2,box3,box4,nil];
[box3 drawRect:box3.frame];
}
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFontSize(context, 11.5);
CGContextSelectFont(context, "Helvetica", 10.5, kCGEncodingMacRoman);
CGContextShowText(context, "Tys", 5);
CGContextShowTextAtPoint(context, 50, 60, "value", 5);
}
但我测试时没有显示任何文字。
【问题讨论】:
-
我不确定问题出在哪里 - 我发布的代码对我来说效果很好。另外,请确保 CGContextShowText 和 CGContextShowText 中的最后一个参数是您要绘制的文本的 strlen。
-
顺便说一句,在 viewDidLoad 中直接调用 drawRect 是完全错误的。如果你想重绘组件,你应该调用 [box3 setNeedsDisplay];
-
您也可以尝试在此处查看用法示例:codesearch.google.com/…
标签: iphone ios uiimageview