2017-07-19 120 views

回答

3

您可以更改字体样式和大小的功能:

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView 

例如:

let pickerDataSource: [String] = (1...10).map { "Option " + String(format: "%2d", $0)} 

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { 
    let label = (view as? UILabel) ?? UILabel() 

    label.textColor = .red 
    label.textAlignment = .center 
    label.font = UIFont.systemFont(ofSize: 20) 

    label.text = pickerDataSource[row] 

    return label 
    } 
} 
+0

由于生病尝试 – jean

+0

我有:VAR的选择= [ “SortBy:”,“日期(升序)“,”日期(降序)“,”燃烧的卡路里(降序)“,”持续时间(降序)“]我如何将它放入我的选取器视图? – jean

+0

@jean请尝试:'''let pickerDataSource:[String] = [“Date(ascending)”,“Date(descending)”,“Calories Burned(descending)”,“Duration(descending)”]''' – javimuu