Gugulethu
Gugulethu

Reputation: 1436

Adding inline Labels to a UIPicker in swift

I have been searching around and cannot figure our how I can do the following. I have a UIPickerView (as shown in the image) I have modified to allow me to pick the min and seconds from but I would also like to add labels like CountDownTimer UIPickerView (shown) so the user can know the minutes from seconds.

Any ideas on how to add the inline labels.

enter image description here

enter image description here

Upvotes: 1

Views: 1228

Answers (1)

sarac
sarac

Reputation: 56

Although not beautiful and probably a better way out there, but you can always create a single value component for "hours" and separately for "min".

var hours = ["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"]
var hoursLabel = ["hours"]
var minutes = ["00","15","30","45"]
var minutesLabel = ["min"]

You may also want to adjust your column widths... here's an example.

//Adjust width of each picker column
func pickerView(pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {

    if (component == 1) {
        return 55 //hours label
    } else {
        return 40 // all others
    }
}

Upvotes: 2

Related Questions