【问题标题】:Sizing a UIPickerView inside a UIAlertView在 UIAlertView 中调整 UIPickerView 的大小
【发布时间】:2016-12-28 11:30:41
【问题描述】:

我正在尝试将UIPickerView 放入UIAlertView,但我似乎无法正确调整它的大小。这是我得到的:

这是我的代码:

    let alertView = UIAlertController(title: "Select item from list", message: "", preferredStyle: UIAlertControllerStyle.alert)

    let pickerView = UIPickerView(frame: CGRect(x: 0, y: 0, width: 250, height: 60))
    pickerView.dataSource = self
    pickerView.delegate = self

    alertView.view.addSubview(pickerView)

    let action = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)

    alertView.addAction(action)
    parent.present(alertView, animated: true, completion: nil)

【问题讨论】:

标签: swift uipickerview uialertview


【解决方案1】:

诀窍是:

  • 使用多行消息为新视图留出空间
  • 在显示警报视图时调整新视图的大小

    let alertView = UIAlertController(
        title: "Select item from list",
        message: "\n\n\n\n\n\n\n\n\n",
        preferredStyle: .alert)
    
    let pickerView = UIPickerView(frame:
        CGRect(x: 0, y: 50, width: 260, height: 162))
    pickerView.dataSource = self
    pickerView.delegate = self
    
    // comment this line to use white color
    pickerView.backgroundColor = UIColor.lightGray.withAlphaComponent(0.2)
    
    alertView.view.addSubview(pickerView)
    
    let action = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)
    
    alertView.addAction(action)
    present(alertView, animated: true, completion: { _ in
        pickerView.frame.size.width = alertView.view.frame.size.width
    })
    

【讨论】:

  • 这会被应用商店拒绝吗?
  • @VlpplpRyguy 我在 .actionSheet 样式上有这个技巧,并且没有被 App Store 拒绝。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多