I need a UIDatePicker
for selecting Month and Year only. I checked the class reference documents. Looks like UIDatePicker
is a UIView
. I imagined UIPickerView
may be a sub view and I can hide the component if I can grab it. But no. That was not possible. Do I have to create my own custom picker then? Any ideas?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
I just reset the day to first of the month when the value change event happens as below. So When the user selects a day, it scrolls back to 1st. I use following for selecting Start date (month & year).
For selecting the End Date (month & year) it is little bit longer, because I wanted to set the day to 31st or 30th of the month selected.
You can use UICustomDatePicker to show only the month and year option
https://github.com/Anandsan/UICustomDatePicker
Refer the Screen
You can use the open source library named
https://github.com/ali-cs/AKMonthYearPickerView
to install it using pods,
to customize previous years limit and bar color
No, this cannot be done using the stock
UIDatePicker
.Source: UIDatePicker class reference
I recommend customizing a
UIPickerView
to use two components and populating its rows with month and year symbols retrieved fromNSDateFormatter
.I have a lazy workaround-- I made a 10x10 black png. I then used that as a mask with a scaletofill imageview sized to cover the dates column perfectly. I put the alpha at 0.75 to barely show that column. It is clear to the user and looks decent.
You can very easily hide the day column like this:
Enjoy :)