Quantcast
Channel: Active questions tagged uipickerview - Stack Overflow
Viewing all articles
Browse latest Browse all 592

PickerView not showing viewForRow - Swift - Programmatically

$
0
0

I'm setting up a UIPickerView and in order to do that I decided to use the method viewForRow of the UIPickerViewDelegate which returns a UIView.

The pickerView shows correctly but the "selected" state of the picker, the one which should represent the element selected with the full alpha gradient doesn't appear.

I can only see the elements when they're NOT in the selected state.

This is the actual code:

class DurationPickerView: UIPickerView {let inView : UIView = {    let view = UIView(frame: .init(x: 0, y: 0, width: 50, height: 50))    let imageView = UIImageView(image: #imageLiteral(resourceName: "infinity").withRenderingMode(.alwaysOriginal))    imageView.tintColor = .white    view.addSubview(imageView)    imageView.fillSuperview()    return view}()let tfView : UIView = {   let view = UIView(frame: .init(x: 0, y: 0, width: 50, height: 50))    let label = UILabel(text: "24h", font: UIFont(name: "avenir-black", size: 20), textColor: .white, textAlignment: .center        , numberOfLines: 0)    view.addSubview(label)    label.fillSuperview()    return view}()}extension DurationPickerView : UIPickerViewDelegate{func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat        {    return 50}func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {    switch row {    case 0:        return inView    default:        return tfView       }    }} extension DurationPickerView : UIPickerViewDataSource{func numberOfComponents(in pickerView: UIPickerView) -> Int{    return 1  }func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{    return 2}}

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>