iOS - 更改 UIPickerView 组件宽度
我知道我可以使用委托方法 – pickerView:widthForComponent:
设置 UIPickerView 的组件宽度,但是如果我有 2 个组件,而我只想更改第一个组件的宽度width 并将第二个组件的宽度保留为默认值(iOS SDK 会计算出的值)。我将如何实现这一目标?
I know I can set the UIPickerView
´s component width with the delegate method – pickerView:widthForComponent:
but say if I have 2 components and I only want to change the first component's width and leave the second component's width to the default value (something that iOS SDK would figure out). How would I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
PickerView 根据选择器中有多少组件来划分组件。所以组件没有默认值。但你仍然可以尝试这个。
为此,请尝试按百分比样式设置组件宽度。
这是屏幕截图:
PickerView divide your component on the basis of how much component there are in picker. so there are no default value for component . but you can still try this .
For that , try to set your component width by percentage style .
Here is screenShot :
除非您使用 if 语句并手动设置默认值(在找出它是什么之后),如下所示:
我不确定您是否可以仅为某些组件设置值,但让默认值接管其他组件。
Unless you use an if-statement and manually set the default value (after finding out what it is) like this:
I'm not sure you can set the value for only some of the components but let the default take-over for others.
这是一个迟来的答案,但对于未来的读者来说,显然没有办法返回“默认”宽度。定义
pickerView:widthForComponent:
方法时,您必须显式设置所有组件的宽度,而不仅仅是其中一些组件的宽度。This is a late answer, but for future readers, apparently there is no way to return a "default" width. The moment you define the
pickerView:widthForComponent:
method, you'll have to explicitly set all the components' widths, not just some of them.