我是一名有帮助的助手,可以为您翻译以下it技术相关内容。该段内容涉及iOS应用程序中的形状绘制问题,使用UIImage子类视图和UIBezierPath来绘制形状线条。
以下是绘制文本的代码:
以下是绘制文本的代码:
// This is inside a loop
const unsigned int row = i;
const unsigned int column = j;
NSString* rowColumnId = [[NSString alloc] initWithFormat:@"%d, %d", column, row ];
CGPoint textCoord = shapeCoord[0];
textCoord.x += 5;
textCoord.y += 5;
[rowColumnId drawAtPoint:textCoord withFont:[UIFont fontWithName:@"Helvetica" size:9.0]];
屏幕上看起来一切正常;在 iOS 模拟器和我的 iOS 设备上,形状和文本都可见。
我需要将视图保存为 PNG 图像,所以我使用了以下代码:
// set up the rendering context
CGSize boardViewSize = [self bounds].size;
UIGraphicsBeginImageContext(boardViewSize);
[[self layer] renderInContext:UIGraphicsGetCurrentContext()];
// draw the view
UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// convert to PNG
NSData* pngData = UIImagePNGRepresentation(viewImage);
UIImage* pngImage = [UIImage imageWithData:pngData];
return pngImage;
当我保存PNG时,我只看到了形状。
为了保存绘制的NSString文字,需要什么代码?