在storyboard中使用浮点值 [英] Using float values in storyboard

查看:144
本文介绍了在storyboard中使用浮点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为故事板中的UIButtons框架分配一个浮点值。

I want to to assign a float value to a UIButtons frame in Storyboard.

但我只能使用int值。是否不鼓励使用.5例如?因为我有一些按钮,我想根据原来的photoshop设计放置他们。

But I can only use int values. Is it discouraged to use .5 for example? because I have some buttons and I want to place them according to the original photoshop design.

例如我有一个按钮我需要放置在X:151,如何我可以实现吗?

for example I have a button I need to be placed at X:151 , how can I achieve that?

推荐答案

不要使用浮点值。正如你正确地观察到的,Interface Builder阻止了这一点;但是你不应该在代码中这样做。恰恰相反:当您在代码中分配帧(或相关组件)时,应首先将其设置为一个整数值。 (事实上​​,还有 CGRectIntegral 等功能可以帮助你。)

Do NOT use a float value. As you have rightly observed, Interface Builder prevents this; but you should not do it even in code. Just the opposite: when you assign a frame (or related component) in code, you should set it to an integral value first. (In fact, there are even functions such as CGRectIntegral to help you.)

原因是,可能会结束在屏幕上的像素之间的,并且视图将无法正确显示(因为没有半像素的东西)。使用整数点,以便您使用整像素数。

The reason is that otherwise you can end up between pixels on the screen, and the view will not display correctly (because there is no such thing as half a pixel). Stick to whole numbers of points so that you are using whole numbers of pixels.

这篇关于在storyboard中使用浮点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆