UIView 代码与界面生成器

发布于 2024-12-20 19:30:13 字数 665 浏览 2 评论 0原文

在此处输入图像描述我在名为矩形0的头文件中定义了一个 UIView

我有一个关于 IB 与编码 a 的问题看法。请参阅以下代码示例:

rectangle0.frame = CGRectMake(0.0, 70.0, 320.0, 190.0);

现在我可以在 IB 中轻松地重新创建视图的外观,除了灰显的坐标之外。

因此,在 IB 中设计 UIView 之后,通过在 IBAction 中调用此代码,我可以在应用程序中显示。

[self.view addSubview:rectangle0];

现在,如果我对其进行编码,最后一行代码将调用此视图以显示在设置的坐标处 - 但如果我在界面生成器中构建,我可以使其看起来完全相同,但它从 Y 坐标 20 出现(就在状态栏下方) )并且我无法在调用它时设置坐标 - 有办法做到这一点吗?

UIView 正在 ViewController 外部构建,然后在连接检查器中链接到它。

杰夫干杯,

我添加了一张图像来显示我正在使用的屏幕 - 正如您所看到的 x 和 y 坐标显示为灰色,如果我可以将它们设置为其他值,那就太好了。

enter image description hereI have defined a UIView in the header file named rectangle0

I got a question in regards to IB vs coding a view. Please see the following code example:

rectangle0.frame = CGRectMake(0.0, 70.0, 320.0, 190.0);

Now I can re-create the look of the view easy enough in IB except for the coordinates which are greyed out.

So by calling this code in an IBAction after designing the UIView in IB I can display in the app.

[self.view addSubview:rectangle0];

Now the last line of code will call this view to appear at the set coordinates if I code it - but if I build in interface builder I can make it look exactly the same, but it appears from Y coordinate 20 (just under the status bar) and I can't set the coordinate upon calling it - is there a way to do this??

The UIView is being build outside of the ViewController and then linked to it in the connections inspector.

cheers Jeff

I have added an image to show what screen I am using - as you can see the x and y coordinates are greyed out, it would be great if I can set those to something else.

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

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

发布评论

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

评论(2

迟月 2024-12-27 19:30:13

NIB 内的视图只是一个与其他对象一样的对象。它是可重复使用的,我相信这是导致坐标变灰的关键点。

将位置变灰会让开发人员担心视图将放置在哪里。我这么说是因为该位置很大程度上取决于视图对象要添加到的容器。

尽管这只是我个人的意见,我期待听到是否确实有办法做到这一点。

A view inside the NIB is just an object like any other. It is made to be reusable and I believe that is the key point that resulted in the coordinates being greyed out.

Greying out the position makes the developer worry about where is the view going to be placed. I say that because the position is pretty dependent on the container that your view object is going to be added to.

Although it is just my personal opinion and I am looking forward to hearing if there is indeed a way to do that.

空袭的梦i 2024-12-27 19:30:13

您(实际上)说视图是由视图控制器管理的。在调整视图大小之前,您需要将视图控制器的模拟指标中的大小设置更改为“自由形式”。 (默认情况下它可能设置为“无”。)

You (effectively) said the view is managed by a view controller. Before you can resize the view, you need to change the Size setting in the view controller's Simulated Metrics to "Freeform". (It is probably set to "None" by default.)

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