Swift Auto Button Resize - swift

Is there any way I can automatically adjust my buttons' sizes. On iPhone 6 and 7 it looks really good. When I go to iPhone 8 and up the buttons appear to be too small. I was doing some research and I couldn't really find anything. This is also in Swift and Xcode.

You can use constraints that autoresize the button based on text size.
Added images for refrences.

Related

Managing iPhone 5 and iPhone 6 image sizes

I am new to programming and Xcode and struggling with setting image size for iPhone 5 and iPhone 6. Apparently both iPhone 5 and 6 use the #2x image while the 6+ use the #3x image. So i can design the 6+ perfectly, however since both iPhone 5 and 6 use the same image and they have different screen size/ resolution, mu screen design is impacted.
If I design the images as per iPhone 6 size, the images appear too big on iPhone 5 and if I design them as iPhone 5 then they appear to be too small on iPhone 6. This should be simple, what am I missing?
Please help!
Instead of directly using the images you should create an entry for them in the Images.xcassets. Select it in your Project Navigator.
Then drag and drop the #3x or #2x version of your image from the images folder into the list of images in the Images.xcassets window. This will automatically generate a new entry. Then drag the other (#2x or #3x) image into its proper position. It will look like this in the end.
Once that is done you can use it in the UIImageView, or Image for a button or whatever in your Storyboard as just the name without the #2x or #3x.
Now to finally answer your question. You should handle all of the image sizes with constraints in the storyboard. So for instance if you want the same margins on either side of your image you will create constraints between the size of the UIImageView that contains your image and the edge of the Superview. This way the image will be resized for each new screen.
Edited to add Be careful of the Constrain to margins check box as you want to be consistent with using it or not otherwise you will get behavior you didn't plan for. I always uncheck it and have my constraints go to the superview edge, but it doesn't matter as long as you are consistent across your App you won't get confused.

How can I make sure my iOS 7 layouts look the same on iOS 6?

I understand that the UI elements will look different, and that is not what I am worried about. I created a simple app in Xcode 5 that just displays a label right under the status bar. In iOS 7 this looks fine. However, when I run the app on an iOS 6 device, the label appears too far down from the status bar. I know that in iOS 7, y=0 is the top of the screen instead of the bottom of the status bar, so I understand why this is happening, but I can't figure out how to fix it. I have seen solutions using self.edgesForExtendedLayout = UIRectEdgeNone, and others that use the deltas in Interface Builder when Autolayout is turned off, however none of these have worked for me.
How can I fix this (while still using Autolayout)? There must be a better way than just subtracting 20 px from the view's position if the system version is iOS 6.1 or earlier.
You can try using the iOS6/7 deltas on your UIViews in your nib files.
It's located in the size inspector of your UIView.
I think the answer you're looking for is in this tech note. (In short: apply a Vertical Space Constraint anchored to the Top Layout Guide of your view controller.)
Technical Q&A QA1797: Preventing the Status Bar from Covering Your
Views https://developer.apple.com/library/ios/qa/qa1797/_index.html

How to design single storyboard file that supports all iphone screen sizes?

I am using storyboard and xcode 4.6 for designing Iphone app. I have very complex viewscontrollers and some of the subviews(like scrollview's and autocomplete tablviews) have generated dynamically. When app build for iphone 4 everything works fine. But, when using Iphone(retina-4 inch) simulator, I noticed that there is space at the top and bottom of the screen and also some of the subviews (like scrollviews and autocomplete tableviews ..) misplaced and covering other subviews in that viewcontroller. I tried to search and found some are suggesting to design/load two xib files based on screen size. I have enabled both autoresize masks and autolayout, but still the problem persists.
How to design a single storyboard file that is feasible for both Iphone-4 and Iphone-5.
Reference:How to develop or migrate apps for iPhone 5 screen resolution?
Update attached screenshot:
Storyboard file
Thanks in advance...
use the button in the picture below to toggle between retina 4 in and 3.5 inch. use the autosizing tool under the size inspector on the top right to get views to position themselves correctly.

Adjust iPhone 5 Screen Size Without Using Autolayout

Enabling Autolayout in .xib or .storyboard and adding a splash screen of 640px by 1136px enables iPhone 5 resolution support for the taller screen.
However, doing so, my app started to display some funny things where I assume autolayout is not a great idea.
I am wondering if there is a way to enable iPhone 5 device support, i.e. fix app's resolution without using Autolayout? Maybe I can set in the code?
If yes, then I will have no need to create 2 storyboards or nibs to support iOS5- and iOS6.
If you weren't using Autolayout before, you won't need to use it for iPhone 5 support.
When you're putting your interface together, you just need to check your bindings, and toggle between the taller phone size, and the regular phone size, as described here:
Xcode Storyboard displaying the new iPhone 5 screen size?
If your screens look fine in both screen sizes then you're done.
If you are doing a lot of coding to show your UI, then you'll have more work to do.
I found a great answer a couple weeks ago (link below). You will copy and paste your older iPhone Storyboard, rename it to reflect the iPhone 5, and press the button that expands the screen size, found on the bottom of the layout grid. Some minor coding adjustments might be needed, but this sample code is used in the AppDelegate to detect which device is running, and hence, which Storyboard to use. You'll just have to duplicate your interfaces, but these GUI changes can be made without code and without AutoLayout (also good to note that AutoLayout removes iOS 5--and lower--compatibility)
xcode 4.5 how to pick storyboards at launch

iPhone 5 Applications (4 inch Screen) [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to develop or migrate apps for iPhone 5 screen resolution?
I'm (still) trying to convert one of my iPhone applications to iPhone 5, but it still looks like this in the simulator...
What am i doing and why won't it fill up the entire screen?
Have you provided a 4" sized launch image? That's the indicator that tells the OS that your application supports the full screen.
Have you selected in your UIView attributes inspector in XCode iPhone 5 screen size?
Please have a look at the url,
iPhone 5 TabBar not functioning in proper position
Now, in xib, at the right side, under 'Interface Builder Document', put a tick-mark on use autolayout and fix your objects in xib accordinlgy.
Download and install Xcode 4.5 GM. Set a 4-inch launch image for
your app. This is how you get 1136px screen height (without it, you
will get 960px with black margins on top and bottom).
Test your app, and hopefully do nothing else, since everything should work magically if you had set auto resizing masks properly. If you didn't, adjust your view layouts with proper auto resizing masks or look into Auto Layout if you only want to support iOS 6 going forward.
Also note: The auto-rotation API has changed completely, take a look at that as well if your application supports any rotation other than default.