我有一个看起来像这样的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项目