更改pickerView组件位置

时间:2015-12-26 11:58:17

标签: objective-c swift io swift2 uipickerview

我有pickerView有两个组件。基于我的语言,我需要更改组件位置,以便我的第一个组件位于右侧,而我的第二个组件位于左侧。

这就是我想要做的事情:

enter image description here

注意:组件已连接我的意思是从第一个组件中选择一行,第二个组件将重新加载新内容。

我该怎么做?

更新

这是代码:

func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    if IS_Mahalat {  
        return 1
    }else{ // just ostan - shahrestan
        if component == 0  {  //osatn
            return self.ostans.count
        }else{//shahrestan
            return self.ostans[pickerView.selectedRowInComponent(0)]._city.count
        }
    }

}

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    if IS_Mahalat {  
        //return self.mahalat[row].name
        return "sdf"
    }else{//ostan shahrestan
        if component == 0  {  //osatn
            return self.ostans[row].name
        }else{//shahrestan
            print(pickerView.selectedRowInComponent(0))
            return  self.ostans[pickerView.selectedRowInComponent(0)]._city[row]._name
        }
    }
}

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    if !IS_Mahalat {//ostan shahrestan
        if component == 0  {  
             self.picker_ostan.reloadComponent(1)
        }
    }
}

func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
    var myString = view as! UILabel!
    let rowText:String!


    if( view == nil) {
        myString = UILabel()
    }
    if IS_Mahalat {  
        rowText = ""
    }else{  //ostan shahrestan

        if component == 0  {  //osatn
             rowText = self.ostans[row].name
        }else{//shahrestan
             rowText = self.ostans[pickerView.selectedRowInComponent(0)]._city[row]._name
        }
    }
    myString.textAlignment = .Center
    let attributedRowText = NSMutableAttributedString(string: rowText)
    let attributedRowTextLength = attributedRowText.length

    attributedRowText.addAttribute(NSForegroundColorAttributeName, value: UIColor.blueColor(), range: NSRange(location: 0, length: attributedRowTextLength))

    attributedRowText.addAttribute(NSFontAttributeName, value: UIFont(name: FONT_NAME, size: 16.0)!, range: NSRange(location: 0 ,length:attributedRowTextLength))

    myString!.attributedText = attributedRowText



    return myString

}


func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
    if IS_Mahalat {  
        return 1
    }else{ // just ostan - shahrestan
        return 2
    }
}

0 个答案:

没有答案