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
}
Related
I'm new to Swift and i'm trying to get a full paged gallery in swift using an UICollectionView inside a viewController UINavigationController.
My problem is that i cannot figure out how to get a full paged ImageView with a NavigationBar, what i've got now is this:
my situation now
but i'd like to have this (with a transparent navigation bar like it is in the first picture):
what i want to accomplish
I've searched all over the net for many hours, i've tried to:
self.collectionView.contentInset = UIEdgeInsetsMake(0,0,0,0)
or
self.automaticallyAdjustsScrollViewInsets = true
I've also tried to uncheck "Adjusts scroll insets" in Xcode but nothing seems to work.
After two days of searching i've found a solution, in viewController viewDidLoad():
self.navigationController!.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController!.navigationBar.translucent = true
If you don't have a navigationController but only a navigationBar or if you have subclassed UINavigationController:
self.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationBar.translucent = true
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];
Trying to make auto layout work with the keyboard extension. Initially i thought i will make the buttons programmatically but then i realized its better to do it with a xib because of my requirement and multiple screen sizes.
Please see the screenshot below on the current configuration i have made.
Button 2:
Button 1 and issue on the app:
All the constraints configuration looks like this:
All i am trying to do here is to make sure the button fills up the screen width. They can expand in width to match screen sizes and orientations. Somehow i feel that its not able to understand the device width. Do i need to specify something for that?
Thanks
Make sure to set the UIView's dimensions on viewDidLoad so that it looks like something like this:
self.mainView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
I had the same problem and this did the trick for me. Your constraints are just fine.
You do not have a constraint on the distance between the two buttons. Try adding on constraint between the buttons for each button.
Ben Flores answer did the trick for me, too, but I had to put my code in viewDidLayoutSubviews. Otherwise my keyboard would crash and not show up. Swift 3 Version:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let frameSize = self.view.frame.size
self.mainView.frame = CGRect(x: 0, y: 0, width: frameSize.width, height: frameSize.height)
}
I have tableview and textfield in negative frame as it is shown in screenshot now when i start to edit text table's scrollview goes down by 20 or 50 pixel.
the same thing is working fine in iOS6. It's also calling scrollview's delegate method. I cant figure it out.
Help me. Thanks in advance.
Try this code in viewDidLoad or loadView method,
if([self respondsToSelector:#selector(setEdgesForExtendedLayout:)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
self.automaticallyAdjustsScrollViewInsets = FALSE;
}
In iOS 7, the scrollview layout is adjusted as per the translucent property of the navigation bar. It might be your problem.
This is happening due to autolayout. Really if you wanna check then just a second uncheck your autolayout option in your xib and then check. I'm sure i won't go 20 or 50 pixel down.
Solution :
Make vertical difference 0 between tableview and text filed. After that it won't go 20 or 50 pixel down.
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.