UIPickerView won't allow changing font name and size via delegate's `attributedTitleForRow…`

前端 未结 5 929
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-30 22:07

I use the following func to change the font color and font size, the color works but the font name and font size refuse to work.

func pickerView(pickerVi         


        
5条回答
  •  醉话见心
    2020-12-30 22:16

    You can declare the datasource for pickerview

    let arrDataSource:[String] = ["row 1","row 2","row 3"]
    

    then use this array of string as title for row in below function

    func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView
    
    {
        let pickerLabel = UILabel()
        pickerLabel.textColor = UIColor.blackColor()
        pickerLabel.text = arrDataSource[row]
         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
     }
    

提交回复
热议问题