How do I change the color of the text in a UIPickerView under iOS 7?

后端 未结 8 927
花落未央
花落未央 2020-11-30 19:39

I\'m aware of the pickerView:viewForRow:forComponent:reusingView method, but when using the view it passes in reusingView: how do I ch

8条回答
  •  一向
    一向 (楼主)
    2020-11-30 20:19

    Swift 4 (Update to the accepted answer)

    extension MyViewController: UIPickerViewDelegate{
        }
    
        func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
            return NSAttributedString(string: "your-title-goes-here", attributes: [NSAttributedStringKey.foregroundColor: UIColor.white])
        }
    }
    

提交回复
热议问题