ios - 使 UIPickerView 宽度填充 View

标签 ios swift uipickerview

我是 iOS 开发新手,我遇到了一个图形问题: 我创建了一个出现在谷歌地图 View 上方的 UIPickerView。我想让选择器 View 宽度与主视图宽度匹配。 目前,选择器始终占据 View 的 3/4,并且位于左上角:

the picker is not center and does not fill the view

我尝试这样做:

func pickerView(pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
    return self.view.bounds.width
}

但结果是这样的: The text inside picker is center but the picker does not fill the view

这就是我想要的: My goal 任何想法?是否可以在故​​事板中而不是在 swift 中设置它?

最佳答案

您可以为 uipickerview 创建约束。选择选取器 View 并设置以下约束。您可以在 Storyboard中设置约束。

尾随空格:0 前导空格:0 按钮间距:0

https://www.raywenderlich.com/115444/auto-layout-tutorial-in-ios-9-part-2-constraints

关于ios - 使 UIPickerView 宽度填充 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36452501/

相关文章:

ios - 自定义UIPicker控件IOS

iphone - 为什么我在使用 Core Plot 构建 iPhone 应用程序时会看到以下链接器错误?

ios - 如何在 Swift Spritekit 中向我的节点添加触摸和按住手势?

ios - 仅在单击完成按钮时将 UIPickerView 选择添加到 TextField

ios - 我怎样才能从 NSUrlSession 返回一个 NSHttpUrlResponse 状态码

swift - 我如何将 __NSCFArray 复制到 swift 数组中

ios - 除非我先选择不同的行,否则 UIPickerView 不会选择第一行?

ios - x 轴的 webkit 溢出滚动问题?

ios - 使用 AlertController 强制更新应用程序

ios - 禁用 uipopover 点击手势识别器