简体   繁体   English

iPhone UIView大小调整和图像绘制

[英]iPhone UIView Sizing & Image Drawing

I'm developing a custom UIView component. 我正在开发一个自定义UIView组件。 It's a simple little stopwatch, with PNG graphics for all the digits. 这是一个简单的小秒表,所有数字均带有PNG图形。 There are lots of tutorials around, so I'm figuring most of it out on my own. 周围有很多教程,所以我自己解决大部分问题。 But I have two questions: 但是我有两个问题:

First of all, the component will always have a particular size (141 x 32), but I don't know how to specify that from within the UIView subclass. 首先,组件将始终具有特定的大小(141 x 32),但是我不知道如何从UIView子类中指定该大小。 The "frame" property wants me to define not only the width and height, but also the x and y position. “ frame”属性不仅要我定义宽度和高度,还要定义x和y位置。 Of course, I won't know the position until the component is placed into some parent view. 当然,在将组件放置到某些父视图中之前,我不知道位置。 How do I do that? 我怎么做?

Secondly, for drawing the all the digit images within the component, I don't know whether I should create UIImageView objects and lay them out as children, or whether I should just draw the images directly within the view's drawRect method. 其次,对于在组件内绘制所有数字图像,我不知道是否应该创建UIImageView对象并将其作为子对象进行布局,还是不应该直接在视图的drawRect方法内绘制图像。 The stopwatch displays hour:minute:second.tenth data, so there will be at least one image updated ten times per second, and one image updated every second. 秒表显示时:分:秒,十分之一数据,因此至少每秒将更新一幅图像十次,每秒将更新一幅图像。 I could easily reassign the "image" property of the UIImageView, or I could just redraw everything using the UIImages directly. 我可以轻松地重新分配UIImageView的“ image”属性,也可以直接使用UIImages重绘所有内容。

What considerations should I take into account when deciding which drawing strategy to use? 决定使用哪种绘图策略时应考虑哪些因素? Are there some cases where one choice is better than the other? 在某些情况下,一种选择比另一种更好吗?

EDIT: 编辑:

I should also mention that I'm trying to develop this component entirely without XIB files, since I'm trying to get a better understanding of the underlying mechanics of custom component development. 我还应该提到,我试图完全不使用XIB文件来开发此组件,因为我试图更好地了解自定义组件开发的基本机制。

Just put 0,0 for x,y position in the frame initially. 最初只需在帧中的x,y位置放置0,0。 The origin will be set to an actual position when you add it to your view. 将原点添加到视图时,原点将被设置为实际位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM