【问题标题】:How can I convert UIButton to UISlider when it is touched?触摸时如何将 UIButton 转换为 UISlider?
【发布时间】:2020-01-21 15:25:05
【问题描述】:

我一直在想,如何将UIButton 转换为UISlider。我在UIButton 上添加了音乐,我想在触摸它时将其转换为UIslider。我该怎么做?

【问题讨论】:

  • 你为什么不展示你已经尝试过的东西?

标签: ios swift xcode uikit swift5


【解决方案1】:

将滑块放在按钮下方,然后您可以在按钮触摸时隐藏按钮并显示滑块 您还可以在显示或隐藏按钮或滑块时添加动画

【讨论】:

    【解决方案2】:

    从技术上讲,您无法将 UIButton 转换为 UISlider (:D :D)

    方法:

    • 在情节提要的同一位置添加滑块和按钮
    • viewDidLoad()
    button.isHidden = false 
    slider.isHidden = true 
    button.addTarget(self, action: #selector(tapped), for: .touchUpInside)
    
    @objc private func tapped() {
        button.isHidden = true 
        slider.isHidden = false  
    }
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多