# Customizing UIPickerView To Have A Label

**URL:** <https://forums.kodeco.com/t/customizing-uipickerview-to-have-a-label/23305>\
**Category:** iOS\
**Created:** [November 28, 2016, 1:01am UTC](https://forums.kodeco.com/t/customizing-uipickerview-to-have-a-label/23305 "2016-11-28T01:01:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robk331](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/robk331/32/57155_2.png) [@robk331](https://forums.kodeco.com/u/robk331)\
**Post date:** [November 28, 2016, 1:01am UTC](https://forums.kodeco.com/t/customizing-uipickerview-to-have-a-label/23305/1 "2016-11-28T01:01:07Z")

</div>

Hi All,

I’m trying to create a timer and I’d like to label the selected rows with “mins” and “secs”. I’ve tried to add the label to pickerView(viewForRow) but this adds the label for all rows, not just the selected one.

Any ideas on how this apparently simply requirement can be implemented? I’m guessing one way would be to add a UILabel in the right spots on top of the picker but that seems a bit inelegant…

Thanks

Rob

PS I’m using Swift.

---

<div class="post-metadata">

**Author:** ![fusetech](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/fusetech/32/97552_2.png) [@fusetech](https://forums.kodeco.com/u/fusetech)\
**Post date:** [November 28, 2016, 3:51am UTC](https://forums.kodeco.com/t/customizing-uipickerview-to-have-a-label/23305/2 "2016-11-28T03:51:33Z")

</div>

Hi Rob,

I agree that overlaying a label on a picker is not ideal. Here are a few things you can try:

See if the UIDatePicker can be configured in a way that meets your timer needs. I see some options for count down timer, but am not sure to what extent you timer is different.

Use 4 components instead of 2. Component 1 with have a single value of “minutes” and 3 will have “seconds”, while 0 and 2 are actually used for picking.

In UIPickerViewDelegate.didSelectRow, save which row was selected. Then in UIPickerViewDataSource.titleForRow, if row == selectedRow, you can return the value plus “Minutes”. This one still feels a bit fragile.

Good luck

---

<div class="post-metadata">

**Author:** ![robk331](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/robk331/32/57155_2.png) [@robk331](https://forums.kodeco.com/u/robk331)\
**Post date:** [November 29, 2016, 12:22am UTC](https://forums.kodeco.com/t/customizing-uipickerview-to-have-a-label/23305/3 "2016-11-29T00:22:57Z")

</div>

That worked, thanks!

Rob
