如何水平设置pickerview

时间:2016-04-04 06:01:52

标签: swift uipickerview

UIPickerView的默认滚动设置设置为垂直。是否可以在swift(picker视图)中水平实现UIPickerView 包含数组也必须改为水平)

不使用任何第三方文件

如果是的话,请你给我看样品 代码在下面

self.rangePickerView.hidden = false
self.rangePickerView.dataSource = self
self.rangePickerView.delegate = self

rangePickerView.clipsToBounds = false        
rangePickerView.layer.borderWidth = 0        
rangePickerView.dataSource = self
rangePickerView.delegate = self

self.rangePickerView.frame = CGRectMake(screenSize.width * 0.06,screenSize.height *
            0.02,screenSize.width * 0.89,screenSize.height*0.46)
self.rangePickerView.transform = CGAffineTransformRotate(self.rangePickerView.transform, CGFloat(-M_PI_2))

self.view.addSubview(rangePickerView)        


//delegate methods//////

func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int
{
    return 1
}

func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
{
     return titles.count
}

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?      
{
    return titles[row]as String  
} 

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
    print("Your favorite city is \(titles[row] )")
    rangePickerView.hidden = false
}

func pickerView(pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat 
{
    return 200  
}

func pickerView(pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat 
{
    return 50
}

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

通过转换选择器视图,查看此链接,了解如何在没有第三方文件的情况下执行此操作 - http://torishere.github.io/swift/2015/02/12/horizontal-uipickerview.html 否则,使用AKPickerview进行水平选择,并使用tag属性来区分您想要的两个AKPickerviews。所以在pickerView(titleForItem)例如,检查pickerView.tag == 0或tag == 1并返回标题的不同字符串。