1
如何更改选取器视图的字体样式和大小?我在拾取器视图设置中看不到选项。你能以编程方式设置它吗?我正在使用swift 3和 xcode 8.2。在选取器视图中更改字体大小和样式
如何更改选取器视图的字体样式和大小?我在拾取器视图设置中看不到选项。你能以编程方式设置它吗?我正在使用swift 3和 xcode 8.2。在选取器视图中更改字体大小和样式
您可以更改字体样式和大小的功能:
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
}
}
由于生病尝试 – jean
我有:VAR的选择= [ “SortBy:”,“日期(升序)“,”日期(降序)“,”燃烧的卡路里(降序)“,”持续时间(降序)“]我如何将它放入我的选取器视图? – jean
@jean请尝试:'''let pickerDataSource:[String] = [“Date(ascending)”,“Date(descending)”,“Calories Burned(descending)”,“Duration(descending)”]''' – javimuu