我将滑块放在屏幕中间,除了4s外,它在我的所有设备中都正确定位。我无法弄清楚如何使滑块像所有其他设备一样位于屏幕中间而不是右侧。这是我使用的代码:
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
let scaleFactor = UIScreen.mainScreen().bounds.width / 320
middleSlider = UISlider(frame: CGRectMake(125 * scaleFactor, 153 * scaleFactor, 150, 50))
middleSlider.tintColor = UIColor.whiteColor()
middleSlider.minimumTrackTintColor = UIColor.whiteColor()
middleSlider.maximumTrackTintColor = UIColor.whiteColor()
middleSlider.value = 1.0
middleSlider.continuous = true
middleSlider.userInteractionEnabled = true
self.view?.addSubview(middleSlider)
}
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
let scaleFactor = UIScreen.mainScreen().bounds.width / 320
middleSlider = UISlider(frame: CGRectMake(130 * scaleFactor, 650, 200, 150))
middleSlider.tintColor = UIColor.whiteColor()
middleSlider.minimumTrackTintColor = UIColor.whiteColor()
middleSlider.maximumTrackTintColor = UIColor.whiteColor()
middleSlider.value = 1.0
middleSlider.continuous = true
middleSlider.userInteractionEnabled = true
self.view?.addSubview(middleSlider)
}
答案 0 :(得分:1)
要使滑块居中,您可以按照以下步骤进行操作
middleSlider = UISlider(frame: CGRectMake(self.view.bounds.width/2 - 150/2, 153 * scaleFactor, 150, 50));
它也将以所有设备为中心。