My app from iOS6 to iOS7 Label issue - ios

i want to change iOS6 application to iOS7.(i.e)i want iOS7 compatibility. When i run my application in iOS7 simulator,view is moving up.
Can someone help me?

The full size of the iPhone Screen (non-retina, for simplicity sake, since that what we use with layout coordinates) is 320x480.
In iOS6 and previous, from a developer standpoint, the screen size was actually 320x460, with a 320x20 strip at the top for the status bar. In iOS6, the point x=0, y=0 translates to the iOS7 point of x=0,y=20.
This is because now the status bar is transparent an you can controller how that 320x20 strip at the top looks.
If you want to support both, you need to check which version of iOS they're using, and if they're using iOS7 or greater, you need to increment the origin.y by 20 pretty much everywhere.
Borrowed from this StackOverflow answer, here is how to programmatically determine which version of iOS is running:
NSString *version = [[UIDevice currentDevice] systemVersion];
int ver = [version intValue];
if (ver < 7) {
//iOS 6 work
} else {
//iOS 7 related work
}

Because by default viewcontroller have extended edges and it will go under top bar, set it to UIedgeRectNone then view will not go under the top bar.
self.edgesForExtendedLayout = UIRectEdgeNone;

Best way to support both iOS6 and iOS7 without much pain is to pack all your view controllers inside navigation controller (with navigation bar set to hidden if necessary).
This will allow to automatically and cleanly handle status bar behaviour changes.

People are nibbling around the correct answer, but haven't given it. I struggled with this for weeks, and finally figured out how to handle it correctly.
How to handle layout differences between iOS 6 and iOS 7 so you can support both without custom code:
The answer is different depending on whether you're using auto-layout or struts and springs.
For auto layout, you tie your top constraints to the "top layout guide", an imaginary line that starts at the content area of the window. It's under any status bar or navigation bar that's present, and moves up if either or both of those items are not shown.
For struts and strings based layout, IB has a mechanism that will let you adjust your view layout automatically.
Select your nib file/storyboard file.
Open the "File inspector" on the right side and look for an item titled "View as". Set that to "iOS 6.1 and earlier. This does several things. It makes your UI look like the app is running under iOS 6, and it makes the geometry work as if it's running under iOS 6.1 rules (the 0.0 point of your content view is under the status bar and your effective screen size is 20 points smaller when the status bar is shown.)
Next, select the views that are pinned to the top of your screen and choose the Size Inspector. (The tab in the utilities area that looks like a ruler). There is a new section of the size inspector called "iOS 6/7 deltas." This lets you specify changes to apply to the selected view when running in the "other" version of iOS than the one you specified above in the file inspector. Since we specified iOS 6, the current layout is using iOS 6 rules, so we want to specify the changes that are needed when running iOS 7 instead. If we had specified "View as iOS 7" in the file inspector, we'd be seeing an iOS 7 layout, and we'd be specifying changes to make when we run under iOS 6. You can do it either way. However, beware. If you have delta values (described below) and then switch this setting, IB moves stuff around on you in very confusing and destructive ways. Don't do that. Pick a value for the "View as" setting and stick with it for your entire app or you will get very confused and frustrated.
You want to make your navigation bars 20 points taller (They then automatically tint the status bar and adjust their layout so their titles and bar button items don't overlap the status bar.)
You also typically want to make views that are pinned to the top of the screen have a delta Y of 20 points to shift them down to make room for the status bar.
If a view is also pinned to the bottom of the screen so it's size adapts with the screen size, you'll probably also want a delta height of -20 pixels.
It takes some tinkering to get everything working right, but by setting your "iOS 6/7 delta" values correctly, you can create IB files that work correctly on both OS versions without any custom code.
If you DO have custom code to do things like tweak your layout for user interface orientation, though, things get really confusing.

Related

iPhone X compatibility programmatically

I want to make my app compatible with iPhone X. I'm not using storyboard or xibs, just code. When I run my app on the simulator the view overlaps part of the status bar and the home bar at the bottom. Is there a way to programmatically adjust the view so that it fits within the bounds? Any help is appreciated.
I believe the answer you are looking for is called safeAreaInsets, which are basically insets that considers the position of the iphoneX exclusive UI components such as the navigation bar and the home bar.
You should adjust the sizes and constraints of your UI components according to the safe area as opposed to the screen, for and non iphoneX devices, it would be 0, which means it would be the same as adjusting according the the screen sizes instead.
The docs for it is at:
https://developer.apple.com/documentation/uikit/uiview/positioning_content_relative_to_the_safe_area

Status bar overlaps on my view

I have a UIViewController subclass which when I run the app on iOS 7, the status bar shows on top of my view. Is there a way to avoid this? I do not want the status bar to be hidden. Is there a way to show the status bar above my app. I present my view using presentViewController. Please guide what I am missing?
In Xcode, In storyboard there is an option of iOS6/7 delta. set delta Y to 20 pixel of your view, to make compatible with iOS7.For this you have to disable auto layout, you can use auto resizing.
This is quite common issue. Starting from iOS 7 Status Bar is a part of the controller's view. Apple even have added special attribute of UIView in the Interface Builder: iOS 6/7 Deltas. To fix your problem and make your view look the same in different iOS versions, go to Size inspector and set Delta Y to 20.0.

iOS 8 Handle status bar on xib files not storyboard

I have an app that I want to upgrade to iOS 8, but since I found that status bar is being hidden on iPhone in landscape mode, I figured that I need to handle such a behaviour.
I solved this issue on iOS 7 by adding a constraint from the top of the navigation bar to the top of the view ( since I am not using Storyboards, some properties or features are not available through xib like top layout guide ) and used this method:
(UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
return UIBarPositionTopAttached;
}
and it was working like charm, but on iOS 8 when status bar is hidden on landscape, navigation bar appears much taller that it is supposed to be. I may handle through constraints and use rotating events, but I believe there must be better ways to handle it.

iOS 6/7 20px difference using autolayout

I've got a background for the project that I am working on, which includes a 20px coloured bar for the top of an iOS 7 device.
This worked fine without autolayout, setting a 20px delta in storyboard. But now I can't do that, and I am stuck with constraints - which I cannot set on a per-OS basis.
Whatever I do, I seem to end up with the version on iOS 7 being 20px higher than on ios 6... Something I need to rectify, as I also have a bar under that status bar which is coloured for a navigation controller.
I've attached the background image - if I need to modify it to work with autolayout, I'm happy to do that.
There is a "top layout guide" object in your view hierarchy. If you build vertical constraints based on that, they pin to the top of the window if there is no status bar, or under the status bar otherwise. Use that.

Is there a way to view a storyboard scene without running the app?

Im working on an app with a viewcontroller buried deep inside a drill down. Im working with autolayout and would like to view my changes without having to go thru the rest of the app processes.
is there a way to view what a scene will look like onscreen without having to run the entire app?
There is a menu option called simulate document. Unfortunately, newer versions of Xcode no longer have this available for iOS apps, OSX only.
If you only want to see the effect of changing between 3.5inch and 4inch phones, or orientation changes, you can change the simulated metrics on the storyboard. This will show you how your ui elements will lay themselves out based on your autolayout settings. Anything you are doing in your code in your view controller won't take effect since you're not actually running anything. This will only show you results based on things you have set in the storyboard.
To do this, select your view controller on the storyboard and open the Attributes Inspector (Cmd+Option+4).
All of the simulated metrics are likely set to Inferred. You can change the size and orientation here.
Using this you can at least find some errors. Say I have a button at the bottom of the view, but I set the constraint to "Top Space To Superview" instead of bottom. When I change the Size Simulated Metric to the 3.5 inch, this button will be off the bottom of the screen.

Resources