我有一个看起来像这样的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
}
}
答案 0 :(得分:0)
尽管您可以在某种程度上自定义选择器的颜色,但是对于字体,如果您想要高度可定制的选择器,请参考github项目