f2cf74c7
yangbin
1.0.20(4)
|
1
2
3
4
5
6
7
8
9
10
|
//
// StepGoalViewController.swift
// Twear
//
// Created by yangbin on 2021/12/18.
//
import UIKit
class StepGoalViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
|
75a3cd13
daifengyi
feat:launch setting
|
11
|
var buttonTitle: String?
|
f2cf74c7
yangbin
1.0.20(4)
|
12
13
14
15
16
17
18
19
20
21
|
var stepGoalClosure: ((_ steps: Int) -> ())?
private var goalArray: [Int] = {
var array: [Int] = []
for i in 0..<50 {
array.append((i+1)*1000)
}
return array
}()
|
75a3cd13
daifengyi
feat:launch setting
|
22
|
@IBOutlet weak var nextButton: UIButton!
|
f2cf74c7
yangbin
1.0.20(4)
|
23
24
25
26
27
28
29
|
@IBOutlet weak var pickerView: UIPickerView!
private var selectedRow: Int = 0
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
|
75a3cd13
daifengyi
feat:launch setting
|
30
|
self.navigationController?.setNavigationBarHidden(false, animated: true)
|
f2cf74c7
yangbin
1.0.20(4)
|
31
32
33
34
35
36
|
}
override func viewDidLoad() {
super.viewDidLoad()
selectedRow = UserInfo.stepsGoal/1000 - 1
pickerView.selectRow(selectedRow, inComponent: 0, animated: false)
|
75a3cd13
daifengyi
feat:launch setting
|
37
38
39
|
if buttonTitle != nil {
nextButton .setTitle(buttonTitle, for: UIControl.State.normal)
}
|
f2cf74c7
yangbin
1.0.20(4)
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Do any additional setup after loading the view.
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return goalArray.count
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return "\(goalArray[row])"
}
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
var pickerLabel = view as? UILabel
if pickerLabel == nil {
pickerLabel = UILabel()
|
75a3cd13
daifengyi
feat:launch setting
|
61
|
pickerLabel?.font = BoldFont(32)
|
f2cf74c7
yangbin
1.0.20(4)
|
62
|
pickerLabel?.textAlignment = .center
|
75a3cd13
daifengyi
feat:launch setting
|
63
|
pickerLabel?.textColor = UIColor.rgbaColorFromHex(0x333333,alpha: 0.3)
|
f2cf74c7
yangbin
1.0.20(4)
|
64
65
66
67
68
69
70
71
72
73
74
75
76
|
}
if row == selectedRow {
pickerLabel?.attributedText = self.pickerView(pickerView, attributedTitleForRow: selectedRow, forComponent: component)
} else {
pickerLabel?.text = self.pickerView(pickerView, titleForRow: row, forComponent: component)
}
return pickerLabel!
}
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let string = NSMutableAttributedString(string: " \(goalArray[row]) \(LocString("步"))")
let unitLength = LocString("步").count
|
75a3cd13
daifengyi
feat:launch setting
|
77
78
|
string.addAttributes([.foregroundColor: UIColor.rgbColorFromHex(0x333333), .font: BoldFont(40)], range: NSMakeRange(0, string.string.length-1))
string.addAttributes([.foregroundColor: UIColor.rgbColorFromHex(0x555555), .font: BoldFont(14)], range: NSMakeRange(string.length-unitLength, unitLength))
|
f2cf74c7
yangbin
1.0.20(4)
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
return string
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
selectedRow = row
pickerView.reloadAllComponents()
}
func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 40
}
@IBAction func saveStepGoal(_ sender: Any) {
stepGoalClosure?(goalArray[selectedRow])
|
75a3cd13
daifengyi
feat:launch setting
|
93
|
// navigationController?.popViewController(animated: true)
|
f2cf74c7
yangbin
1.0.20(4)
|
94
95
96
97
98
99
100
101
102
103
104
105
106
|
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
|