2017-07-19 101 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

相關問題