I'm using Xcode beta 7 with the iOS9 simulator.
Using a UIDatePicker with a datePickerMode of UIDatePickerModeTime only shows Hours, and not minutes.
See screenshot:
On iOS 7 and 8, obviously it works as expected, and shows both Hours and Minutes. Screenshot:
I really do not want to reinvent the wheel and roll my own time picker. Any ideas on why this might be happening and how to fix? I can't find anything on google.
thanks,
Alex
I encountered this after the public release of iOS 9.0 with a UIDatePicker using UIDatePickerModeDate in my tableview.
I hacked around it by changing the UIDatePicker mode right before it was displayed, and then changing it back to the desired one:
[myDatePicker setDatePickerMode:UIDatePickerModeDateAndTime];
[myDatePicker setDatePickerMode:UIDatePickerModeDate];
I'm guessing redrawing it solves the issue. For interest's sake I don't think it's actually an issue of not displaying the minutes but rather a bug in the subviews because this is what mine looked like:
Inspecting using FLEX, this is part of the UIDatePicker that has a solid white background.
Found a useful description of this problem in the iOS 9 release notes - seems I should be reading these more carefully.
UIPickerView and UIDatePicker are now resizable and adaptive—previously, these views would enforce a default size even if you attempted to resize them. These views also now default to a width of 320 points on all devices, instead of to the device width on iPhone.
Interfaces that rely on the old enforcement of the default size will likely look wrong when compiled for iOS 9. Any problems encountered can be resolved by fully constraining or sizing picker views to the desired size instead of relying on implicit behavior.
iOS 9 Release Notes
In my case all I had to do was remove all constraints on the UIDatePicker and then "Reset to Suggested Constraints". Rebuild and now all is well.
I had an issue when upgrading Xcode to 7.0.
When the UIDatePicker was displayed the middle portion was blank, as per LordParsley's answer.
The height of the UIDatePicker for iOS 9 is 216; whereas earlier versions the height is 162, and forcing the height to 162 resolved the issue.
Since my view is defined within a storyboard, I setup a height constraint on the UIDatePicker and set the height to 162 for iOS versions < 9.0, within the view's viewDidLoad.
- (void) viewDidLoad {
[super viewDidLoad];
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 9.0) {
//
// NOTE: iOS 9, or Xcode 7, now sets UIDatePicker height at 216; whereas,
// iOS 8, or Xcode 6.x, set it at 162.
//
// If the height is left at 216, then on iOS 7.1, the middle portion of the
// UIDatePicker control is missing. Setting the hieght to 162 fixes the issue
// within this application.
//
// UIDatePicker frame cannot be used to adjust the size, therefore use a
// height contraint to change the size.
//
self.dateHeightConstraint.constant = 162;
}
}
#LordParsley solution did the trick.
Just some additional details:
I notice it occurs on iPhone 5 series and not on iPhone 6/6 plus with leading and trailing constraints. Apparently the bug only appears when its frame width is 320. Probably its a miscalculation of picker subviews that causes the overlaps. This is quite funny because Apple is the one who set the default value and yet they've oversaw the issue.
Anyways I hope this gets resolved with iOS 9.1 which is now in beta.
I have same issue when running my app in iOS 9, my app using UIDatePicker in .xib file.
I resolved this problem by add it in code behind:
UIDatePicker* picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 320, 162)];
[self.view addSubview:picker];
I think, this's problem with new font San Francisco (the font is big than Helvetica) and .xib file.
Hope this help.
Thank!
On iPhone 5S iOS 9.1 my month names are truncated when I display the UIDatePicker. I fixed this problem by setting a local property as follows:
NSLocale *uk = [[NSLocale alloc] initWithLocaleIdentifier:#"en_US"];
NSCalendar *cal = [NSCalendar currentCalendar];
[cal setLocale:uk];
[_backdateDatePicker setCalendar:cal];
Related
I am having weird bugs in IB for tvOS tableviewcells.
Since this is my first tvOS project, I don't know if it is intended or not but tableviewcell's content view's width is notably smaller than actual cell.
When I try to add any subview(UILabel, UIButton or UIView) its actual frame and content are different.
Lastly, when I try to resize any subview inside UITableViewCell, its frame changes immediately.
Screenrecord1
I use the latest version of Xcode, Version 9.2 (9C40b). Has anyone else experienced this issue before?
In each of my xibs it asked me what default device do I want to use. I chose iPhone 6 and updated the frames to the suggested ones. Now, any view that was affected in the viewWill or viewDidLayoutSubviews is messed up. They all have frames of CGRect(0, 0, 1000, 1000).
Here's my code:
self.headImage.layer.cornerRadius = ceilf(CGRectGetWidth(self.headImage.frame)/2);
self.headImage.layer.masksToBounds = YES;
Wondering what's up with this and whether there is a solution. Thanks
I resolved my issue by calling
myOwnView.layoutIfNeeded()
before getting the myOwnView.frame
If even viewDidLayoutSubviews gives you the wrong frame - calling layoutIfNeeded on layoutSubviews can do the trick!
override func layoutSubviews() {
super.layoutSubviews()
yourView.layoutIfNeeded()
setGradientForYourView()
}
This issue was happening to me when I was returning from a pushed ViewController and in ViewDidLayoutSubviews frame was incorrect.
My view's width constraint was set to be proportional to parent view's width and there was no constant offsets. I replaced this proportionality constraint with offset constraints and frame is now calculated correctly.
This issue was on XCode 10, iOS 12, iPhone 6 Plus.
good morning :)
i have a problem with my datepicker in ios 9 swift 2
this is how my datepicker looks like in ios 8 swift 2 [OK]:
and this is my datepicker in ios 9 swift 2 [NOT OK]:
Any ideas how i can solve it?
I had similar issue with UILabel and UIDatePicker in same cell.
I figure out that setting witch for UIDatePicker based on container view width. Will cause this error, for ex:
Leading and Tailing to container view
Equal width as container view
But when you set width as:
Given width ex. 400
Equal width as UILable above
I hope this will help someone.
PS. I've set gray background for better look. First screen shot shows that UIDatePicker have some issues with rendering. I'm only guessing.
I had same issue and was able to resolve it by adding datepicker using this code:
UIDatePicker* picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 320, 162)];
[self.view addSubview:picker];
I faced similar problem due to pinning Date Picker to container height & width, solution which worked for me was to also add constraint for width and & height from storyboard auto layout as below -
AppsWise
I hade the same issue while working with a picker within another cell.
Simply adding constraints worked like a charm for me.
Why i need to add constraints to a picker in swift 2 i still don't know.
Hope this helps.
I had a similar issue when adding a UIDatePicker programmatically into a complex UIView heirarchy. I just ended up using brute force, like so:
let datePicker = UIDatePicker()
datePicker.setDate(NSDate(), animated: false)
datePicker.datePickerMode = .Date
var tempFrame = datePicker.frame
let originalDatePickerWidth = tempFrame.size.width
if originalDatePickerWidth != self.view.bounds.width
{
tempFrame.size.width = self.view.bounds.width
tempFrame.size.height *= (self.view.bounds.width / originalDatePickerWidth)
datePicker.frame = tempFrame
}
I spent several days trying to see the working UIScrollView horizontal scroll indicator (without AutoLayout) on iOS7 (on iPad). But without success.
Has anyone fixed such bug?
My project is simple and running iOS5 and iOS6 without troubles.
I found out, that on iOS7 height of the scroll indicator image is always zero:
UIImageView * scrollBar = [[scrollView subviews] lastObject];
if (scrollBar != nil)
{
PrintRect(#"FRAME", scrollBar.frame);
PrintRect(#"BOUNDS", scrollBar.bounds);
}
Result for iOS7:
FRAME x:0.000000 y:54.000000 w:338.000000 h:0.000000
BOUNDS x:0.000000 y:0.000000 w:338.000000 h:0.000000
but for iOS6:
FRAME x:0.000000 y:47.000000 w:338.000000 h:7.000000
BOUNDS x:0.000000 y:0.000000 w:338.000000 h:7.000000
So the height scroll bar image on iOS7 is equal to zero.
It's possible to change the height, but only for a quick time because during drugging the height becames zero again.
I was stuck on something similar. I am doing the CS193P course on iTunes and there was this scrollView exercise - Imaginarium. Basically it's just a UIImageView embedded in a UIScrollView. I was having the same problem that the scroll indicators were not being displayed (with Autolayout turned off)
I looked up the header file for UIScrollView in the documentation and there is this property in scrollView called scrollIndicatorInsets:
The distance the scroll indicators are inset from the edge of the scroll view.
#property(nonatomic) UIEdgeInsets scrollIndicatorInsets
It goes on to say that the default value is UIEdgeInsetsZero!! So I created a UIEdgeInset using UIEdgeInsetsMake (see documentation). Then in viewDidLoad I set this UIEdgeInsets to be my scrollView's scrollIndicatorInsets, after which my indicators appeared when I scrolled.
Hope this works for you too.
Didn't have this issue at all until I began adapting my app for iOS 6. Whenever I return from a modal segue (with dismissViewControllerAnimated:completion:), my main view is shifted up by about the status bar's height worth of offset (and is subsequently behind the status bar).
The only workaround I've found is to add:
self.navigationController.view.frame = CGRectMake(0, 20, 320, 460);
self.view.frame = CGRectMake(0, 0, 320, 416);
to my dismissViewControllerAnimated:completion method (those values are for an iPhone < 5 and are just for explanation). But this doesn't really solve the problem, because when I go to present the next modal view controller, the presented view is then shifted up by about the status bar's height worth of offset.
No idea how this issue arose. My suspicion is that, somewhere in the segue, one of the navigation controllers loses track of the status bar's existence (linked to the new status bar, in some way?).
EDIT:
a screenshot of the main view, post-modal dismissal. [Note: 20px whitespace on the bottom]
Resolved the issue. My custom navigationController's supportedInterfaceOrientations was returning UIInterfaceOrientationPortrait, rather than UIInterfaceOrientationMaskPortrait.
Your answer didn't work for me either but I found this solution by Mike Foster that did:
http://fostah.com/ios/2012/09/27/ios6-orientation-handling.html
His steps are:
add the applications supportedInterfaceOrientation and have it return UIInterfaceOrientationMaskAll (or in my case I used AllButUpsideDown)
In your rootViewController implement shouldAutorotate and have it return NO
DO NOT implement supportedInterfaceOrientations in your rootViewController (this seems to be the step that was causing problems with the status bar for me)
In the viewController that should be landscape implement shouldAutorotate to return NO and supportedInterfaceOrientations to return UIInterfaceOrientationMaskLandscape
Hopefully that helps a few other people.
This answer didn't work for me, even though I have the same structure with a custom navigationController as the rootViewController. In my app, I want it in portrait for all VCs except for my modals, which will be UIInterfaceOrientationMaskAll.
What did work was a variation on your workaround, except it will account for iPhone 4 and iPhone 5 screen sizes and the height of the navBar:
[yourParentVC dismissViewControllerAnimated:NO completion:^{
[yourParentVC.view setFrame:CGRectMake(0, 0, [UIScreen mainScreen].applicationFrame.size.width, [UIScreen mainScreen].applicationFrame.size.height-44)];
//your other completion code
}];
+1 for asking this question...not happy how much work it's been accounting for all the deprecations in iOS 6, so every little bit helps.