简体   繁体   English

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

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

I have an SB that look like this 我有一个看起来像这样的SB

在此处输入图片说明

It yields this result 它产生这个结果

I'm trying to increase the font of my picker. 我正在尝试增加选择器的字体。

What would be the best way to about this ? 最好的方法是什么?

Is this something that I can achieve via the storyboard settings? 这是我可以通过情节提要设置来实现的东西吗?

I have this 我有这个

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
    }


}

Although you can customize the color of the picker to some extent but for font no possible option is available if you want a highly customizable picker refer to github projects 尽管您可以在某种程度上自定义选择器的颜色,但是对于字体,如果要高度自定义的选择器请参考github项目,则没有可用的选项

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

https://github.com/itsmeichigo/DateTimePicker https://github.com/itsmeichigo/DateTimePicker

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

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