-1
其實,我想在UIPickerView
中只顯示兩行以上的數據。所以,無論用戶何時向上/向下滾動,用戶都只能顯示兩行。如何只顯示2行UIPickerView?
獲得我想要的東西更多的想法通過看下面的圖片:
我曾嘗試下面的代碼
var pickerDataSource = ["1", "2", "3", "4","5","6", "7", "8", "9","10","11","12"];
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView
{
var label = view as! UILabel!
if label == nil {
label = UILabel()
}
let titleData : String?
titleData = pickerDataSource[row]
if row == pickerView.selectedRowInComponent(0)
{
let myTitle = NSAttributedString(string: titleData!, attributes: [NSFontAttributeName: UIFont(name:"Montserrat-Regular", size: 16.0)!,NSForegroundColorAttributeName:UIColor.lightGrayColor()])
label.attributedText = myTitle
}
else
{
let myTitle = NSAttributedString(string: titleData!, attributes: [NSFontAttributeName: UIFont(name:"Montserrat-Regular", size: 16.0)!,NSForegroundColorAttributeName:UIColor.redColor()])
label.attributedText = myTitle
}
label.textAlignment = .Center
return label
}
這將改變該行的顏色,但我怎麼只設置兩排。
有什麼辦法可以達到這樣的效果嗎?
選取器視圖顯示儘可能多的行,因爲它可以放在視圖中。您唯一的選擇是告訴選取者您的排是非常高的。 – rmaddy
@rmaddy如何隱藏底部行,需要隱藏所選行的底部 –