gpt4 book ai didi

ios - 使用 sambag 时间选择器时出现问题

转载 作者:行者123 更新时间:2023-11-28 13:55:26 26 4
gpt4 key购买 nike

我正在使用 sambag 时间选择器 Controller ,我在 sambag picker 方法的按钮上设置了时间,但问题是我在一个 View Controller 中有多个按钮,所以我在设置时为每个设置时间方法都做了这个按钮所有按钮标题都改变我想要的是只改变我按下的按钮的值

在这里,我将向您展示我的尝试,我将向您展示我的代码

   import UIKit

class ManageHoursViewController: UIViewController {

var theme: SambagTheme = .light

var result : String!
@IBOutlet weak var btnMonStartTime: UIButton!
@IBOutlet weak var btnMonEndTime: UIButton!
@IBOutlet weak var btnMonOff: UIButton!
@IBOutlet weak var btnMonOn: UIButton!


override func viewDidLoad() {
super.viewDidLoad()
round()

let hh2 = (Calendar.current.component(.hour, from: Date()))
let mm2 = (Calendar.current.component(.minute, from: Date()))
print(hh2)
print(mm2)
let dateTime = "\(hh2) : \(mm2)"
btnMonStartTime.setTitle("\(dateTime)", for: .normal)
btnMonEndTime.setTitle("\(dateTime)", for: .normal)
// Do any additional setup after loading the view.
}

func round(){

btnMonOff.isHidden = true
btnMonStartTime.layer.cornerRadius = btnMonStartTime.frame.height / 2
btnMonStartTime.layer.shadowColor = UIColor(red: 154/255, green: 154/255, blue: 154/255, alpha: 1).cgColor
btnMonStartTime.layer.shadowOffset = CGSize(width: 0, height: 1)
btnMonStartTime.layer.shadowOpacity = 1.0
btnMonStartTime.layer.shadowRadius = 2.0
btnMonStartTime.layer.masksToBounds = false

btnMonEndTime.layer.cornerRadius = btnMonEndTime.frame.height / 2
btnMonEndTime.layer.shadowColor = UIColor(red: 154/255, green: 154/255, blue: 154/255, alpha: 1).cgColor
btnMonEndTime.layer.shadowOffset = CGSize(width: 0, height: 1)
btnMonEndTime.layer.shadowOpacity = 1.0
btnMonEndTime.layer.shadowRadius = 2.0
btnMonEndTime.layer.masksToBounds = false
}

@IBAction func btnMonStartTimeTapped(_ sender: UIButton) {
let vc = SambagTimePickerViewController()
vc.theme = theme
vc.delegate = self
present(vc, animated: true, completion: nil)
}
@IBAction func btnMonEndTimeTapped(_ sender: UIButton) {
let vc = SambagTimePickerViewController()
vc.theme = theme
vc.delegate = self
present(vc, animated: true, completion: nil)
}
}
extension ManageHoursViewController : SambagTimePickerViewControllerDelegate {

func sambagTimePickerDidSet(_ viewController: SambagTimePickerViewController, result: SambagTimePickerResult) {
self.result = "\(result)"
print(self.result)
btnMonStartTime.setTitle(self.result, for: .normal)
btnMonEndTime.setTitle(self.result, for: .normal)
viewController.dismiss(animated: true, completion: nil)
}

func sambagTimePickerDidCancel(_ viewController: SambagTimePickerViewController) {
viewController.dismiss(animated: true, completion: nil)
}
}

我想当星期一开始时间按钮按下然后我选择时间表单选择器然后只有星期一开始时间按钮值更改现在所有按钮值都更改

最佳答案

您可以创建一个 var 来跟踪最后一次点击

 var lastBu: UIButton!


@IBAction func btnMonStartTimeTapped(_ sender: UIButton) {
let vc = SambagTimePickerViewController()
vc.theme = theme
vc.delegate = self
lastBu = sender
present(vc, animated: true, completion: nil)
}
@IBAction func btnMonEndTimeTapped(_ sender: UIButton) {
let vc = SambagTimePickerViewController()
vc.theme = theme
vc.delegate = self
lastBu = sender
present(vc, animated: true, completion: nil)
}

关于ios - 使用 sambag 时间选择器时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53945267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com