繁体   English   中英

在iOS中增加选取器的大小-Swift 4

[英]Increase the Size of Picker in iOS - Swift 4

我有一个看起来像这样的SB

在此处输入图片说明

它产生这个结果

我正在尝试增加选择器的字体。

最好的方法是什么?

这是我可以通过情节提要设置来实现的东西吗?

我有这个

extension ScreenTimeViewController : UIPickerViewDelegate, UIPickerViewDataSource {

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 2
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return component == 0 ? 25 : 61
    }

    func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {

        if view != nil {
            view?.layer.backgroundColor = UIColor.white.cgColor
            view?.layer.cornerRadius = (view?.bounds.width)! / 2

            return view!
        } else {

            let newView = UIView(frame: CGRect(x: 0, y: 0, width: 110, height: 40))

            newView.layer.masksToBounds = false
            newView.layer.backgroundColor = UIColor.white.cgColor
            newView.layer.cornerRadius = newView.bounds.width / 2

            switch component {
            case 0:
                addLabel(in: newView, at: CGPoint(x: newView.bounds.minX + 20, y: newView.bounds.midY), text: "\(row)", color: .black)
            case 1:
                addLabel(in: newView, at: CGPoint(x: newView.bounds.minX + 20, y: newView.bounds.midY), text: "\(row)", color: .black)
            default:
                break
            }

            return newView
        }

    }

    func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
        return 110
    }

    func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
        return 50
    }


}

尽管您可以在某种程度上自定义选择器的颜色,但是对于字体,如果要高度自定义的选择器请参考github项目,则没有可用的选项

https://github.com/mithyer/DatePicker-Swift

https://github.com/itsmeichigo/DateTimePicker

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM