http://blog.csdn.net/wangxiaobupt/article/details/47035423
UIProgressView
显示一个UIProgressView
-
import UIKit
-
-
class ViewController: UIViewController {
-
-
override func viewDidLoad() {
-
super.viewDidLoad()
-
-
let progressView = UIProgressView(progressViewStyle: .Bar)
-
progressView.center = view.center
-
progressView.progress = 20.0/30.0
-
progressView.trackTintColor = UIColor.lightGrayColor()
-
progressView.tintColor = UIColor.blueColor()
-
view.addSubview(progressView)
-
-
}
-
-
}
效果如下:
UISlider
显示一个UISlider
-
import UIKit
-
-
class ViewController: UIViewController {
-
-
var slider: UISlider!
-
-
override func viewDidLoad() {
-
super.viewDidLoad()
-
-
slider = UISlider(frame: CGRect(x: 0, y: 0, width: 200, height: 23))
-
slider.center = view.center
-
slider.minimumValue = 0
-
slider.maximumValue = 100
-
slider.value = slider!.maximumValue / 2.0
-
view.addSubview(slider)
-
-
}
-
-
}
效果如下:
给UISlider添加事件
-
import UIKit
-
-
class ViewController: UIViewController {
-
-
var slider: UISlider!
-
-
func sliderValueChanged(slider: UISlider){
-
print("Slider's new value is \(slider.value)")
-
}
-
-
override func viewDidLoad() {
-
super.viewDidLoad()
-
-
slider = UISlider(frame: CGRect(x: 0, y: 0, width: 200, height: 23))
-
slider.center = view.center
-
slider.minimumValue = 0
-
slider.maximumValue = 100
-
slider.value = slider!.maximumValue / 2.0
-
-
slider.addTarget(self,
-
action: "sliderValueChanged:",
-
forControlEvents: .ValueChanged)
-
-
view.addSubview(slider)
-
-
}
-
-
}
定制简单的UISlider
设置了不同状态下,滑块的图片。
-
import UIKit
-
-
class ViewController: UIViewController {
-
-
var slider: UISlider!
-
-
override func viewDidLoad() {
-
super.viewDidLoad()
-
-
slider = UISlider(frame: CGRect(x: 0, y: 0, width: 200, height: 23))
-
slider.center = view.center
-
slider.minimumValue = 0
-
slider.maximumValue = 100
-
slider.value = slider!.maximumValue / 2.0
-
-
slider.setThumbImage(UIImage(named: "ThumbNormal"), forState: .Normal)
-
slider.setThumbImage(UIImage(named: "ThumbHighlighted"), forState: .Highlighted)
-
-
view.addSubview(slider)
-
-
}
-
-
}
效果如下:
阅读(838) | 评论(0) | 转发(0) |