swift 實踐- 11 -- UISlider

來源:互聯網
上載者:User

標籤:imp   uiview   滑塊   animate   表徵圖   set   port   響應   pos   

import UIKit

 

class ViewController: UIViewController {

 

    override func viewDidLoad() {

        super.viewDidLoad()

        

        let slider = UISlider.init(frame: CGRect.init(x: 0, y: 0, width: 300, height: 50))

        slider.center = self.view.center

        slider.minimumValue = 0

        slider.maximumValue = 1

        slider.value = 0.5

        self.view.addSubview(slider)

        

        // 設定滑塊的值  有動畫

        slider.setValue(0.5, animated: true)

        

        // 滑塊值改變響應

        slider.isContinuous = false // 滑塊滑動停止之後才會觸發 ValueChanged 事件

        slider.addTarget(self, action: #selector(sliderChange(slider:)), for: .valueChanged)

        

        

        // 滑塊左右兩邊槽的顏色

        slider.minimumTrackTintColor = UIColor.red

        slider.maximumTrackTintColor = UIColor.green

        

        

        

        

        

        // 滑塊後面槽線兩側添加表徵圖

        slider.minimumValueImage=UIImage(named:"2")  //左邊表徵圖

        slider.maximumValueImage=UIImage(named:"2")  //右邊表徵圖

        

    

        //設定滑塊的圖片

        slider.setThumbImage(UIImage(named:"2"),for:.normal)

    }

    

    func sliderChange(slider:UISlider){

        print(slider.value)

    }

        

 

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }

 

 

}

 

swift 實踐- 11 -- UISlider

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.