【问题标题】:How to Draw some sample images on the iPhone?如何在 iPhone 上绘制一些示例图像?
【发布时间】:2011-01-18 20:30:01
【问题描述】:

我只想在iPhone上画一些简单的圆圈,我认为使用openGL做这个示例工作太复杂了,但我发现UIB没有像canvas这样的东西,任何关于在iPhone上绘制示例图像的建议?非常感谢。

【问题讨论】:

    标签: iphone graphics iphone-sdk-3.0 opengl-es quartz-graphics


    【解决方案1】:

    创建一个扩展 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));
    }
    

    【讨论】:

      【解决方案2】:

      你试过iPhonedocumentation吗?您正在寻找一个 UIView。链接的文档为您提供了一个很好的概述,其中包含对更具体信息的引用。那个页面上甚至还有代码示例。

      【讨论】:

        猜你喜欢
        • 2011-06-26
        • 2012-04-20
        • 1970-01-01
        • 1970-01-01
        • 2015-02-08
        • 1970-01-01
        • 1970-01-01
        • 2021-12-21
        相关资源
        最近更新 更多