0
我想實現viewForRow
委託,所以我可以爲每一行有兩個標籤。我現在只用一行標籤就可以工作。任何幫助,高度讚賞。兩個標籤爲每行picker查看
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
var returnLabel = view as UIView!
if view == nil {
returnLabel = UIView()
}
var pickerLabel = view as! UILabel!
if view == nil {
pickerLabel = UILabel()
}
let titleData = List
let myTitle = NSAttributedString(string: titleData[row], attributes: [NSFontAttributeName:UIFont(name: "Helvetica Neue", size: 17.0)!,NSForegroundColorAttributeName:UIColor.whiteColor()])
pickerLabel.attributedText = myTitle
pickerLabel.textAlignment = .Center
var pickerLabel2 = view as! UILabel!
if view == nil {
pickerLabel2 = UILabel()
}
let subtitleData = subtitleList
let mySubtitleTitle = NSAttributedString(string: subtitleData[row], attributes: [NSFontAttributeName:UIFont(name: "Helvetica Neue", size: 12.0)!,NSForegroundColorAttributeName:UIColor.whiteColor()])
pickerLabel2.attributedText = mySubtitleTitle
pickerLabel2.textAlignment = .Left
returnLabel.addSubview(pickerLabel)
returnLabel.addSubview(pickerLabel2)
return returnLabel
}
func pickerView(pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 60
}
你的意思是你想在你的選擇器視圖兩列和每行每列都應該有自己'UILabel'? – rmaddy