默认UIPickerView高度 [英] Default UIPickerView height

查看:168
本文介绍了默认UIPickerView高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据应用当前正在运行的设备的分辨率和方向以编程方式获取UIPickerView实例的默认高度?

How can I programatically obtain the default height of an UIPickerView instance, in accordance to the resolution and orientation of the device that the app is currently running on?

I如果新设备支持不同的屏幕分辨率,并且因此将确定此组件具有不同的默认大小,则不希望对此参数使用硬编码值。

I would like not to use a hardcoded value for this parameter, in the event that new devices will support different screen resolutions and thus will determine this component to have a different default size.

推荐答案

André看到的警告似乎不再发生(XCode 4.2; iOS SDK 5.0)。如果你用 initWithFrame 创建它并给它一个零的高度,你可以从 frame.height property:

The warning that André saw doesn't seem to happen anymore (XCode 4.2; iOS SDK 5.0). If you create it with initWithFrame and give it a height of zero, you can then read back it's height from the frame.height property:

uiPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 77, 320, 0)];
DLog(@"uiPickerView=%@",uiPickerView);

给出:

uiPickerView=<UIPickerView: 0x9a28c40; frame = (0 77; 320 216); layer = <CALayer: 0x9a28d00>>

所以216是默认高度。

So 216 is the default height.

我在标题中找不到这个的定义,所以阅读它似乎是最安全的方式。

I couldn't find a definition for this in the headers, so reading it back seems to be the safest way.

可以设置一个非框架 - 零高度,但Apple表示不这样做,而且似乎会导致渲染问题。

It is possible to set a frame with a non-zero height, but Apple say don't do that, and it seems to cause rendering problems.

这篇关于默认UIPickerView高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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