绘制形状和按钮

发布于 2024-09-24 22:10:00 字数 1156 浏览 0 评论 0原文

iPhone 开发的学习曲线没有我预期的那么陡峭。在遵循了一些教程和 Apress 的优秀书籍“Beginning iPhone 3 Development”之后,一切都进展顺利。当然,当我遇到困难时,这个论坛到目前为止给了我很大的帮助。到目前为止,我从未在我过去工作过的任何平台上进行过任何“图形”编程,所以这对我来说是一个高度未知的领域,特别是在 iPhone 上。我还没有找到一个很好的信息来源,所以我希望这里的一些人可以直接帮助我,或者为我找到一个具有绘画的瓦尔哈拉的来源(书籍,网站);)

我想做的是一个像绘图一样的甘特图。这些块上应该有一些文本解释该块的含义以及用户可以点击的按钮(自定义形状,例如星形)。按钮在切换时需要更改颜色。

我能够找到并尝试的是:创建一个单独的视图,然后在该视图上实现此代码:

- (void)drawRect:(CGRect)rect {
    //Get the CGContext from this view
    CGContextRef context = UIGraphicsGetCurrentContext();


    //Draw it
    CGContextStrokePath(context);

    //Draw a rectangle
    CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
    //Define a rectangle
    CGContextAddRect(context, CGRectMake(40.0, 10.0, 100.0, 60.0));
    //Draw it
    CGContextFillPath(context);
}

到目前为止一切顺利,但我现在陷入困境。我的问题是:

  • (0,0) 坐标在纵向模式下位于左上角,但我的图表需要在横向模式下查看,并且转换所有内容并不是那么容易,所以我想知道是否可以更改坐标系。

  • 如何在该矩形中绘制文本

  • 我如何知道该矩形对于我的文本来说足够大

  • 如何在该矩形中创建一个功能按钮

  • 不太重要,但当我问...如何绘制一个图表中更奇特的块。当前的块只是一个普通的平面颜色,但如果能绘制一个更像 iCal 的块(带有渐变)就更好了。

一个大蒂亚!

The learning curve for iPhone development has been less steep than I expected. After following some tutorials and the excellent book "Beginning iPhone 3 Development" by Apress things have gone quite ok. And of course when I got stuck this forum has been a great help so far. Until now I never did any 'graphical' programming on any platform I worked on in the past so this is highly uncharted territory for me in general en on the iPhone specific. I haven't been able to find a great source for info yet so I hope that some here can either help me directly or pinpoint me to a source (book, site) with the walhalla of drawing ;)

What I want to make is a gantt chart like drawing. The blocks should have some text on it explaining what that block is about and a button (custom shape eg a star) where the user can tap on. The button needs to change color when it's toggled.

What I've been able to find and try out is: create a separate view, and then implement this code on that view:

- (void)drawRect:(CGRect)rect {
    //Get the CGContext from this view
    CGContextRef context = UIGraphicsGetCurrentContext();


    //Draw it
    CGContextStrokePath(context);

    //Draw a rectangle
    CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
    //Define a rectangle
    CGContextAddRect(context, CGRectMake(40.0, 10.0, 100.0, 60.0));
    //Draw it
    CGContextFillPath(context);
}

So far so good but I'm stuck now. My problems are:

  • the (0,0) coordinates are top left in portrait mode, but my chart needs to be viewed in landscape mode, and converting everything isn't that easy afaik, so I was wondering if I can change the coordinate system.

  • How do I draw text in that rectangle

  • How do I know the rectangle is big enough for my text

  • How do I create a functioning button in that rectangle

  • Less important but while I'm asking... How do I draw a more fancy block in the chart. The current block is just a plain flat color, but it would be nice to draw a block a bit more iCal-like (with gradients).

a big TIA !!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情哥ㄟ 2024-10-01 22:10:00

关于如何绘制文本并将其固定到矩形中,您可以参见 这篇文章
NSString UIkit 插件提供了一些额外的方法来绘制所需大小的字符串。

About how to draw text and fix this into the rectangle, you can see this article.
NSString UIkit addon provides some extra methods for drawing string with desired size.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文