How do I change the font size in a UIPickerView in Swift?
如何在选取器视图中更改字体大小?我已经阅读了很多关于此的问题,但没有一个在 Swift 3 中。我有三个选择器视图;前两个有两列,并且具有相同的数据源和委托。最后一个有一个列,并且具有不同的数据源和委托。我无法将前两个选取器视图中的文本放在一个字符上。如有必要,如何缩小 UIPickerView 中的字体大小并调整选择器视图行高?谢谢。
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
class ViewController: UIViewController {
//MARK: Properties @IBOutlet weak var layoutLengthPicker: UIPickerView! let layoutLengthPickerDelegate = DimensionsPickerDelegate() override func viewDidLoad() { layoutLengthPicker.delegate = layoutLengthPickerDelegate layoutWidthPicker.delegate = layoutWidthPickerDelegate trackPicker.delegate = trackPickerDelegate // Do any additional setup after loading the view, typically from a nib. //MARK: Actions override func didReceiveMemoryWarning() { } class DimensionsPickerDelegate: NSObject, UIPickerViewDataSource, UIPickerViewDelegate { let feet = ["0 Ft.","1 Ft.","2 Ft.","3 Ft.","4 Ft.","5 Ft.","6 Ft.","7 Ft.","8 Ft.","9 Ft.","10 Ft.","11 Ft.","12 Ft.","13 Ft.","14 Ft.","15 Ft.","16 Ft.","17 Ft.","18 Ft.","19 Ft.","20 Ft.","21 Ft.","22 Ft.","23 Ft.","24 Ft.","25 Ft.","26 Ft.","27 Ft.","28 Ft.","29 Ft.","30 Ft.","31 Ft.","32 Ft.","33 Ft.","34 Ft.","35 Ft.","36 Ft.","37 Ft.","38 Ft.","39 Ft.","40 Ft.","41 Ft.","42 Ft.","43 Ft.","44 Ft.","45 Ft.","46 Ft.","47 Ft.","48 Ft.","49 Ft.","50 Ft.","51 Ft.","52 Ft.","53 Ft.","54 Ft.","55 Ft.","56 Ft.","57 Ft.","58 Ft.","59 Ft.","60 Ft.","61 Ft.","62 Ft.","63 Ft.","64 Ft.","65 Ft.","66 Ft.","67 Ft.","68 Ft.","69 Ft.","70 Ft.","71 Ft.","72 Ft.","73 Ft.","74 Ft.","75 Ft.","76 Ft.","77 Ft.","78 Ft.","79 Ft.","80 Ft.","81 Ft.","82 Ft.","83 Ft.","84 Ft.","85 Ft.","86 Ft.","87 Ft.","88 Ft.","89 Ft.","90 Ft.","91 Ft.","92 Ft.","93 Ft.","94 Ft.","95 Ft.","96 Ft.","97 Ft.","98 Ft.","99 Ft.","100 Ft."] let inches = ["0 In.","1 In.","2 In.","3 In.","4 In.","5 In.","6 In.","7 In.","8 In.","9 In.","10 In.","11 In.","12 In."] func numberOfComponents(in pickerView: UIPickerView) -> Int { func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { } } class TrackPickerDelegate: NSObject, UIPickerViewDataSource, UIPickerViewDelegate { let manufacturers = ["Atlas True Track","Atlas Code 100","Atlas Code 83","Bachmann Nickel Silver","Bachmann Steel Alloy","Kato","Life-Like Trains Code 100","LIfe-Like Trains Power-Loc","Peco Code 100","Peco Code 83","Peco Code 75","Shinohara Code 100","Shinohara Code 70","Walthers"] func numberOfComponents(in pickerView: UIPickerView) -> Int { func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { } |
在 Swift 3.x 上试试这个:
填写您的字体名称、颜色、大小
n
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/268577.html