2016-10-11 6 views
0

ピッカービューのテキストフォントと色を変更しようとしています。しかし、私がそれをすると、私はエラーが出るので、助けてください。ピッカービューでエラーが発生しました

func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? { 
    let attributedString = NSAttributedString(string: "some string", attributes: [NSForegroundColorAttributeName : UIColor.red]) 
    return attributedString 
} 

ErrorImage

答えて

0

私はあなたがUIPickerViewDataSourceはあなたが実装したいメソッドを実装する必要があり、この

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { 
      let pickerLabel = UILabel() 
      pickerLabel.textColor = UIColor.black 
      pickerLabel.text = "\(dataSource[row])" 

      pickerLabel.font = UIFont(name: "OpenSans-Light", size: 70) 
      pickerLabel.textAlignment = NSTextAlignment.center 
      return pickerLabel 
     } 

func numberOfComponents(in pickerView: UIPickerView) -> Int { 
     return 1 
    } 

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 
     return dataSource.count 
    } 
0

のようなビューを提供することにより、そのようなことをしました。これらを含める:

func numberOfComponents(in pickerView: UIPickerView) -> Int 

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int 

例:

func numberOfComponents(in pickerView: UIPickerView) -> Int { 
    return 1 
} 

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 
    return 10 
} 
関連する問題