【发布时间】:2011-01-18 20:30:01
【问题描述】:
我只想在iPhone上画一些简单的圆圈,我认为使用openGL做这个示例工作太复杂了,但我发现UIB没有像canvas这样的东西,任何关于在iPhone上绘制示例图像的建议?非常感谢。
【问题讨论】:
标签: iphone graphics iphone-sdk-3.0 opengl-es quartz-graphics
我只想在iPhone上画一些简单的圆圈,我认为使用openGL做这个示例工作太复杂了,但我发现UIB没有像canvas这样的东西,任何关于在iPhone上绘制示例图像的建议?非常感谢。
【问题讨论】:
标签: iphone graphics iphone-sdk-3.0 opengl-es quartz-graphics
创建一个扩展 UIView 的类并实现 drawRect 方法:
- (void)drawRect:(CGRect)rect
{
// Get the graphics context and clear it
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect);
// Draw a red solid square
CGContextSetRGBFillColor(ctx, 255, 0, 0, 1);
CGContextFillRect(ctx, CGRectMake(10, 10, 50, 50));
// Draw a green solid circle
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(100, 100, 25, 25));
}
【讨论】:
你试过iPhonedocumentation吗?您正在寻找一个 UIView。链接的文档为您提供了一个很好的概述,其中包含对更具体信息的引用。那个页面上甚至还有代码示例。
【讨论】: