From f9997f748c459ee263d4579004014f1d85f0d072 Mon Sep 17 00:00:00 2001 From: daifengyi Date: Mon, 22 May 2023 22:49:17 +0800 Subject: [PATCH] feat:user info page UI --- HDFwear.xcodeproj/project.pbxproj | 4 ++++ HDFwear/AppDelegate.swift | 10 +++++----- HDFwear/Basic/View/ZCStringPickerView.swift | 226 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ HDFwear/Mine/Base.lproj/Mine.storyboard | 10 +++++----- HDFwear/Mine/UserInfoSettingVC.swift | 36 +++++++++++++++++++++++++++++------- HDFwear/Mine/View/SettingCell4.swift | 1 + HDFwear/Mine/View/SettingCell4.xib | 40 ++++++++++++++++++++-------------------- HDFwear/Mine/View/SettingCell5.xib | 28 ++++++++++++++++------------ 8 files changed, 306 insertions(+), 49 deletions(-) create mode 100644 HDFwear/Basic/View/ZCStringPickerView.swift diff --git a/HDFwear.xcodeproj/project.pbxproj b/HDFwear.xcodeproj/project.pbxproj index 054668d..2839094 100644 --- a/HDFwear.xcodeproj/project.pbxproj +++ b/HDFwear.xcodeproj/project.pbxproj @@ -288,6 +288,7 @@ B23AA1052A18F22600BB3902 /* SortPageSectionHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = B23AA1042A18F22600BB3902 /* SortPageSectionHeader.swift */; }; B23AA1082A18F3F100BB3902 /* SortPageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B23AA1062A18F3F100BB3902 /* SortPageCell.swift */; }; B23AA1092A18F3F100BB3902 /* SortPageCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B23AA1072A18F3F100BB3902 /* SortPageCell.xib */; }; + B262F7C72A1BB71600B4DFD2 /* ZCStringPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B262F7C62A1BB71500B4DFD2 /* ZCStringPickerView.swift */; }; B2AF58822A14C4BE0080B464 /* LaunchMyInfoSettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2AF58812A14C4BE0080B464 /* LaunchMyInfoSettingVC.swift */; }; /* End PBXBuildFile section */ @@ -663,6 +664,7 @@ B23AA1042A18F22600BB3902 /* SortPageSectionHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortPageSectionHeader.swift; sourceTree = ""; }; B23AA1062A18F3F100BB3902 /* SortPageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortPageCell.swift; sourceTree = ""; }; B23AA1072A18F3F100BB3902 /* SortPageCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SortPageCell.xib; sourceTree = ""; }; + B262F7C62A1BB71500B4DFD2 /* ZCStringPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZCStringPickerView.swift; sourceTree = ""; }; B2AF58812A14C4BE0080B464 /* LaunchMyInfoSettingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchMyInfoSettingVC.swift; sourceTree = ""; }; C621CFD20D2BD60CF4F959C3 /* Pods-HDFwear.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HDFwear.release.xcconfig"; path = "Target Support Files/Pods-HDFwear/Pods-HDFwear.release.xcconfig"; sourceTree = ""; }; E7F3880C37BC5F6DD15C709D /* Pods-HDFwear.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HDFwear.debug.xcconfig"; path = "Target Support Files/Pods-HDFwear/Pods-HDFwear.debug.xcconfig"; sourceTree = ""; }; @@ -733,6 +735,7 @@ 6C26010E277C5A5A00EE0B4B /* BottomAlertView.swift */, 6C5B545727756865007F7901 /* DatePickerView.swift */, 6C0D9B972776CA9E00E8C880 /* ZCPickerView.swift */, + B262F7C62A1BB71500B4DFD2 /* ZCStringPickerView.swift */, 6C26010C277C10A400EE0B4B /* ProgressButton.swift */, 6C02891F2746513900A3D91D /* RangeSliderView.swift */, 6C02892127465B1300A3D91D /* RangeSliderView.xib */, @@ -1704,6 +1707,7 @@ 6C1B7EAA27B7977000DB9D1C /* NFCBlankVC.swift in Sources */, 6CCB7FF8276C6C06009EF617 /* RecordHeaderView.swift in Sources */, 6C8F74EA2779B98700B8A1A7 /* UserInfoSettingVC.swift in Sources */, + B262F7C72A1BB71600B4DFD2 /* ZCStringPickerView.swift in Sources */, 6C5CD63227785180003747E1 /* SMSRemindVC.swift in Sources */, 6C41D0C8275F5DB500747BE4 /* LoaderBallPulseAnimation.swift in Sources */, 6C2EE975277FF2520051413A /* AppSettings.swift in Sources */, diff --git a/HDFwear/AppDelegate.swift b/HDFwear/AppDelegate.swift index 8e00126..3e9004b 100644 --- a/HDFwear/AppDelegate.swift +++ b/HDFwear/AppDelegate.swift @@ -31,13 +31,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate { object_setClass(Foundation.Bundle.main, HDFBundle.self) - if AdminHelper.shared.isFirstLaunch() { +// if AdminHelper.shared.isFirstLaunch() { window?.rootViewController = LaunchViewController() window?.makeKeyAndVisible() - } else { - window?.rootViewController = ZCTabBarController() - window?.makeKeyAndVisible() - } +// } else { +// window?.rootViewController = ZCTabBarController() +// window?.makeKeyAndVisible() +// } initSDK() return true diff --git a/HDFwear/Basic/View/ZCStringPickerView.swift b/HDFwear/Basic/View/ZCStringPickerView.swift new file mode 100644 index 0000000..fdf8f03 --- /dev/null +++ b/HDFwear/Basic/View/ZCStringPickerView.swift @@ -0,0 +1,226 @@ +// +// DatePickerView.swift +// Twear +// +// Created by yangbin on 2021/12/24. +// + +import UIKit + +class ZCStringPickerView: UIView, UIPickerViewDelegate, UIPickerViewDataSource { + + typealias clickAlertClosure = (_ value: String) -> Void + var clickClosure: clickAlertClosure! + + private let bgView = UIView() //白色框 + + private lazy var titleLabel: UILabel = { + let label = UILabel() + label.font = RegularFont(20) + label.textColor = UIColor .rgbColorFromHex(0x333333) + label.textAlignment = .center + return label + }() + + private lazy var sureBtn: UIButton = { + let button = UIButton() + button.addTarget(self, action: #selector(clickBtnAction(_:)), for: .touchUpInside) + button.layer.cornerRadius = 22 + button.layer.masksToBounds = true + button.backgroundColor = UIColor .rgbColorFromHex(0x24C789) + button.setTitle(LocString("确定"), for: .normal) + button.titleLabel?.font = BoldFont(17) + button.tag = 1 + return button + }() + + private lazy var cancelBtn: UIButton = { + let button = UIButton() + button.addTarget(self, action: #selector(clickBtnAction(_:)), for: .touchUpInside) + button.setImage(UIImage(named: "close"), for: .normal) + button.tag = 2 + return button + }() + + var selectedRow: Int = 0 { + didSet { + pickerView.selectRow(self.selectedRow, inComponent: 0, animated: false) + pickerView.reloadAllComponents() + } + } + + lazy var pickerView: UIPickerView = { + let picker = UIPickerView() + picker.delegate = self +// picker.locale = .current +// picker.addTarget(self, action: #selector(dateChanged(datePicker:)), for: .valueChanged) + return picker + }() + + private var suffix: String? + private var titleColor: UIColor = UIColor.rgbColorFromHex(0x333333) + private var values: [String] = [] +// { +// didSet { +// pickerView.reloadAllComponents() +// } +// } + + init(title: String, values: [String], suffix: String? = nil, sureText: String = LocString("确定")) { + super.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT)) + createView(title: title, values: values, suffix: suffix, sureText: sureText) + } + + + func createView(title: String, values: [String], suffix: String? = nil, sureText: String) { + self.backgroundColor = UIColor.black.withAlphaComponent(0.1) + + bgView.backgroundColor = .white + self.suffix = suffix + self.values = values + titleLabel.text = title + sureBtn.setTitle(sureText, for: .normal) + +// pickerView.reloadAllComponents() + + addSubview(bgView) + bgView.addSubview(titleLabel) + bgView.addSubview(sureBtn) + bgView.addSubview(cancelBtn) + bgView.addSubview(pickerView) + + bgView.snp.makeConstraints { (make) in + make.left.right.bottom.equalToSuperview() + make.height.equalTo(340) + } + cancelBtn.snp.makeConstraints { make in + make.height.equalTo(78) + make.width.equalTo(58) + make.right.top.equalToSuperview() + } + + sureBtn.snp.makeConstraints { make in + make.bottom.equalToSuperview().offset(-50) + make.left.equalToSuperview().offset(60) + make.right.equalToSuperview().offset(-60) + make.height.equalTo(44) + } + + titleLabel.snp.makeConstraints { make in + make.centerX.equalToSuperview() + make.centerY.equalTo(cancelBtn) + } + pickerView.snp.makeConstraints { make in + make.top.equalTo(cancelBtn.snp_bottom) + make.left.right.equalToSuperview() + make.bottom.equalTo(sureBtn.snp_top) + } + + + bgView.layoutIfNeeded() + bgView.setCorners(corners: [.topLeft, .topRight], radio: 12) + } + + + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return values.count + } + + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return "\(values[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() + pickerLabel?.font = RegularFont(16) + pickerLabel?.textAlignment = .center + pickerLabel?.textColor = UIColor.lightGray + } + 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, rowHeightForComponent component: Int) -> CGFloat { + return 30 + } + + func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? { + let str = "\(values[row])" + var string = NSMutableAttributedString(string: "\(values[row])") + if suffix != nil { + if suffix == ":00" { + string = NSMutableAttributedString(string: "\(String(format:"%02d",values[row])):00") + string.addAttributes([.foregroundColor: titleColor, .font: RegularFont(23)], range: NSMakeRange(0, string.length)) + } else { + string = NSMutableAttributedString(string: " \(values[row]) \(suffix!)") + string.addAttributes([.foregroundColor: titleColor, .font: BoldFont(16)], range: NSMakeRange(0, string.length-1)) + string.addAttributes([.foregroundColor: titleColor, .font: BoldFont(20)], range: NSMakeRange(0, str.length+1)) + string.addAttributes([.foregroundColor: titleColor, .font: BoldFont(16)], range: NSMakeRange(str.length+1, suffix!.length+1)) + } + } else { + string.addAttributes([.foregroundColor: titleColor, .font: BoldFont(20)], range: NSMakeRange(0, str.length)) + } + + return string + } + + func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { + selectedRow = row + pickerView.reloadAllComponents() + } + + + + + @objc func clickBtnAction(_ sender: UIButton) { + if clickClosure != nil && sender.tag == 1 { + clickClosure!(values[selectedRow]) + } + dismiss() + } + + func show() { + let wind = KeyWindow + self.alpha = 0 + + wind.addSubview(self) + UIView.animate(withDuration: 0.25, animations: { () -> Void in + self.alpha = 1 + }) + } + + @objc func dismiss() { + UIView.animate(withDuration: 0.25, animations: { () -> Void in + self.alpha = 0 + }, completion: { (finish) -> Void in + if finish { + self.removeFromSuperview() + } + }) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + /* + // Only override draw() if you perform custom drawing. + // An empty implementation adversely affects performance during animation. + override func draw(_ rect: CGRect) { + // Drawing code + } + */ + +} diff --git a/HDFwear/Mine/Base.lproj/Mine.storyboard b/HDFwear/Mine/Base.lproj/Mine.storyboard index 311370c..7b7815d 100644 --- a/HDFwear/Mine/Base.lproj/Mine.storyboard +++ b/HDFwear/Mine/Base.lproj/Mine.storyboard @@ -748,8 +748,8 @@ - - + + @@ -760,10 +760,10 @@ - - + + - + diff --git a/HDFwear/Mine/UserInfoSettingVC.swift b/HDFwear/Mine/UserInfoSettingVC.swift index a80dac8..9ad4e99 100644 --- a/HDFwear/Mine/UserInfoSettingVC.swift +++ b/HDFwear/Mine/UserInfoSettingVC.swift @@ -159,9 +159,9 @@ extension UserInfoSettingVC: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { if indexPath == [0, 0] { - return 60 + return 64 } else { - return 50 + return 64 } } @@ -183,10 +183,12 @@ extension UserInfoSettingVC: UITableViewDelegate, UITableViewDataSource { } else { cell.detailImageView.image = UIImage(named: user.gender == 1 ? "avatar_male" : "avatar_female") } + cell.setCorners(corners: [.topLeft, .topRight], radio: 10) return cell } else { let cell = tableView.dequeueReusableCell(withIdentifier: "SettingCell4", for: indexPath) as! SettingCell4 cell.titleLabel.text = LocString(settingArray[indexPath.section][indexPath.row]) + cell.lineView.isHidden = true switch settingArray[indexPath.section][indexPath.row] { case "昵称": if user.name == "" { @@ -194,16 +196,26 @@ extension UserInfoSettingVC: UITableViewDelegate, UITableViewDataSource { } else { cell.detailLabel.text = user.name } + cell.lineView.isHidden = false + cell.setCorners(corners: [.bottomLeft, .bottomRight], radio: 10) + break case "性别": cell.detailLabel.text = user.gender == 1 ? LocString("男") : LocString("女") + cell.setCorners(corners: [.topLeft, .topRight], radio: 10) + break case "生日": cell.detailLabel.text = user.birth.toString(.custom("yyyy-MM-dd")) + break case "年龄": cell.detailLabel.text = "\(user.age)\(LocString("岁"))" + break case "身高": cell.detailLabel.text = "\(user.height)cm" + break case "体重": cell.detailLabel.text = "\(user.weight)kg" + cell.setCorners(corners: [.bottomLeft, .bottomRight], radio: 10) + break default: break } @@ -233,13 +245,23 @@ extension UserInfoSettingVC: UITableViewDelegate, UITableViewDataSource { } navigationController?.pushViewController(vc, animated: true) case "性别": - let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "ModifyGenderVC") as! ModifyGenderVC - vc.selectedRow = 1-user.gender - vc.genderClosure = {[weak self] gender in - self?.user.gender = gender + let values = ["男", "女"] + let pickerView = ZCStringPickerView(title: LocString("选择性别"), values: values) + pickerView.selectedRow = values.firstIndex(of: user.gender == 1 ? "男" : "女") ?? 0 + pickerView.show() + pickerView.clickClosure = {[weak self] value in + self?.user.gender = value == "男" ? 1 : 0 self?.updateGender() } - navigationController?.pushViewController(vc, animated: true) + + +// let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "ModifyGenderVC") as! ModifyGenderVC +// vc.selectedRow = 1-user.gender +// vc.genderClosure = {[weak self] gender in +// self?.user.gender = gender +// self?.updateGender() +// } +// navigationController?.pushViewController(vc, animated: true) case "生日": let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "ModifyBirthdayVC") as! ModifyBirthdayVC vc.birthdayClosure = {[weak self] date, age in diff --git a/HDFwear/Mine/View/SettingCell4.swift b/HDFwear/Mine/View/SettingCell4.swift index 92ab6c7..4de383e 100644 --- a/HDFwear/Mine/View/SettingCell4.swift +++ b/HDFwear/Mine/View/SettingCell4.swift @@ -9,6 +9,7 @@ import UIKit class SettingCell4: UITableViewCell { + @IBOutlet weak var lineView: UIView! @IBOutlet weak var detailLabel: UILabel! @IBOutlet weak var titleLabel: UILabel! diff --git a/HDFwear/Mine/View/SettingCell4.xib b/HDFwear/Mine/View/SettingCell4.xib index 0ddad09..a3f3ae8 100644 --- a/HDFwear/Mine/View/SettingCell4.xib +++ b/HDFwear/Mine/View/SettingCell4.xib @@ -1,9 +1,9 @@ - + - + @@ -18,48 +18,48 @@ - + - - + + - - + - - + - - - + + + + diff --git a/HDFwear/Mine/View/SettingCell5.xib b/HDFwear/Mine/View/SettingCell5.xib index 1845a32..5f3b19f 100644 --- a/HDFwear/Mine/View/SettingCell5.xib +++ b/HDFwear/Mine/View/SettingCell5.xib @@ -1,16 +1,16 @@ - + - + - + @@ -18,10 +18,10 @@ - + - - + + @@ -30,15 +30,19 @@ - + + + + + - +