我有另一个选择可能对你有帮助..
完成正常选择器视图所需的所有工作:获取更多帮助UIPickerView make in Swift iOS
现在按照这个步骤: - 你可以像这样使用 viewForRow 的方法
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView
{
var pickerLabel = UILabel()
pickerLabel.textColor = UIColor.blackColor()
pickerLabel.text = "PickerView Cell Title"
// pickerLabel.font = UIFont(name: pickerLabel.font.fontName, size: 15)
pickerLabel.font = UIFont(name: "Arial-BoldMT", size: 15) // In this use your custom font
pickerLabel.textAlignment = NSTextAlignment.Center
return pickerLabel
}
更新了 Swift 3
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView
{
let pickerLabel = UILabel()
pickerLabel.textColor = UIColor.black
pickerLabel.text = "PickerView Cell Title"
// pickerLabel.font = UIFont(name: pickerLabel.font.fontName, size: 15)
pickerLabel.font = UIFont(name: "Arial-BoldMT", size: 15) // In this use your custom font
pickerLabel.textAlignment = NSTextAlignment.center
return pickerLabel
}
更新了 Swift 5
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView
{
let pickerLabel = UILabel()
pickerLabel.textColor = UIColor.white
pickerLabel.text = "PickerView Cell Title"
// pickerLabel.font = UIFont(name: pickerLabel.font.fontName, size: 15)
pickerLabel.font = UIFont.boldSystemFont(ofSize: 20) // In this use your custom font
pickerLabel.textAlignment = NSTextAlignment.center
return pickerLabel
}
可能对你有帮助,我在我的项目中也使用了它。