Why Xcode Storyboard preview and emulator button texts are not compatible? - swift

I am trying to drag and drop buttons to the storyboard. The buttons seem good in my storyboard and preview like the following;
However, when I run the simulator, the button texts seem like the following;
Why the buttons are not shown to fit in the buttons of the simulator and how can I fix this?
Note: Preview and device types are iPhone13 Pro.

The iOS 15 / Xcode 13 style buttons are highly dependent on auto-layout.
Based on your screen-shots, it doesn't look like you've given the buttons any constraints.
You do NOT need to set widths or heights, but you DO want to set at least horizontal and vertical position constraints.
So, constrain all 4 of your buttons centered horizontally, and constrain:
First button Top to view Top (safe area)
Second button Top to First button Bottom
Third button Top to Second button Bottom
Fourth button Top to Third button Bottom
Then you should see them laid-out correctly at run-time.

I think it's because of the auto layout constraints. I am not very familiar with storyboards, if you don't set width of the view component, it seems fine on the storyboard but when compiling the view it actually has default size.
Try to set some constraints for width. Maybe it would help.

The first thing you need to do is to create identical buttons with identical size and with identical font size.
As you can see in your project, the buttons have different sizes, but the text is the same size in all buttons.
To make it faster - you can create one button and make a copy with option + drag’and’drop…
Then, you can put them in a Stack View. So, it will be easier for you to work with them in the future.
Select all buttons and make a Stack View...
https://i.stack.imgur.com/QLTJP.png
https://i.stack.imgur.com/OlOia.png
After that, resize your Stack View like you want.
Then, tap on a Stack View and clear the constraints.
https://i.stack.imgur.com/1pMT8.png
Fix the dimensions like this. But, without “Constrain to mergins”.
https://i.stack.imgur.com/8HKKF
After that, make for the Stack View - horizontally and vertically position in your storyboard.
https://i.stack.imgur.com/a29wL.png
The result is…
https://i.stack.imgur.com/mvQjg.png
Hope it’s break your problem! :)

Related

iPhone - I can't edit the constraints of my navigation bar button [duplicate]

I do have autolayout on, but for some reason my center button isn't being centered for other phone sizes. I have constraints set and like I mentioned autolayout, so I'm somewhat confused. All other items are where they should be, buttons, other labels, etc. One specific label at the top is just off center for all models aside from iPhone 6.
If I am not wrong you didn't add any constraint to your label that's why it is not at center.
Add this constraint for label.
Result for all screen:
i'm just adding video and setting constraints with rightclick on the outlet and selection done with left click
this is tested in all the device so just watch and apply you can solve your problem and if you want to arrange your view so you can add new constraints which is required otherwise you can set these 4 constraints set and execute.
just watch this video and setting your constraints
you tube link to setting constraints in autolayout to centering button

UIButton images look fine in IB but get stretched when displayed on app

I'm developing an Enterprise app for tracking mileage and maintenance for company vehicles. I've added graphic buttons to snazz it up a bit. The buttons look the way they're supposed to look on the XIB in IB, and on the iPhone all other UIViews look correct, but on one particular UIView the graphic images are stretched way out of proportion vertically.
The first image below shows how it's supposed to look, with the three graphics buttons at the bottom. The second image shows how it's showing on the phone. The Help button on this screen cap shows normally, but it can't be counted on to stay that way.
It also is not consistent. Calling this view at any time may show the image stretched or it may not show an image at all. It rarely shows the image normally, like the Help button looks below.
The development phone is a 4S running 6.1.3. The views are set for the Retina 3.5 screen. XCode is the latest (whatever it is).
Again, it's only on this one view that the problem shows up. There is another UIView on the same view controller that is hidden when this UIView is shown. The button graphics on the other view look fine. All of the other views and view controllers use the same graphics on the UIButton, without any problem.
In Interface Builder (Xcode) you created the view using a 4.5-inch screen height.
But the device where you are seeing the problem is a 5-inch screen. So the view is resized to fit.
And when it does that, the autolayout constraints that Interface Builder put on those subviews take over to determine what they do. Those constraints are causing the heights to change.
No need to turn Autolayout off. Autolayout can be very useful, but it seems to enjoy randomly assigning the constraint "Align Baseline to:" to UIButtons after repositioning them.
Just select the UIButton/UIImageView in question inside Storyboard, locate the constraint "Align Baseline to:", tap the gear icon and select "Promote to User Constraint", and tap once more and select "Delete". This should solve your issue.
In response to the comments here, I will answer my own question: I turned Autolayout off for this view controller, and that fixed everything. This is the first app I have written since XCode has begun development for the iPhone 5, so I wasn't aware of the Autolayout feature. I'll need to understand how it works and why it did what it did.
Thanks for all your help!

iOS Interface Builder lock views to right of their table cells

In the form pictured below, as you can see, all of the items are aligned to the right in portrait mode. However, in landscape mode, the text box and switch do not move to the right with the detail items. The detail cells use an apple template, while the ones with the text box and switch are custom cells. How do I set it up in interface builder so that the switch and text boxes move over to the right?
I've been messing with this for a while with no success and haven't found any useful information googling.
If you're using a custom cell, you need to set the autosizing mask to keep the right margin fixed on the views you want to align right, something like this:

UITableView has blank space below, can't remove

I have a UITableView that displays some data that is read in at runtime and features a button below it that will refresh the list when clicked. All of that works fine, however there is a problem with the layout on the simulator.
When I run, there is a space at the bottom of the table that pushes the refresh button down. No matter how long the UITableView is, the UIButton will always be kept at that extended distance. If I overlay the bottom with the UIButton, it does display with slightly less padding. I am at a loss of how to fix this.
Image with example of behaviour: http://img864.imageshack.us/img864/9913/screenshot20120326at113.png
I think the problem is that in the interface builder your layout does not show at the same size, because it lacks the navigation bar at the top.
In the visual editor, choose the window hosting your table view, go to the attribute inspector, and choose Navigation bar for the Top Bar entry in the Simulated Metrics section of the inspector. The layout of your design will change. Resize your table view, move your button, rebuild the app, and run it again; this should do the trick.
It looks like it's because you're designing without the navigation bar simulated and you've set up your autoresizing masks incorrectly.
What you can do is either enable the simulated metric (attributes inspector in IB with the main view selected) for the top bar set to Navigation Bar, or you can go and fix your autoresizing masks. They are the red things in the size inspector in IB.
It is because when you designed the screen you didn't consider the navigation bar that is gonna come. Simply add a bar to the screen on the top and rearrange the table and button with proper autoresizing masks. It will fit.

Scrolling through UIScrollView in Interface Builder for Xcode 4

This seems to me as though it would be a common problem, but I can't seem to find the answer anywhere. This question seems to address the issue, but I can't seem to get the solution to work and I'm not sure it's referring to Xcode 4.
When using Interface Builder in Xcode 4 and working with a UIScrollView, is there a way to scroll the view down in Interface Builder itself to view/add/edit controls that are out of the viewable section of the screen? I've managed to push a couple controls down using the arrow keys, but now I can't see them and therefore can't manipulate them in Interface Builder. Scrolling the view in IB would be first prize, but if there's a way to even select the controls using a drop-down menu or whatever so I can push them back up with the arrow keys, that would at least be something. Thanks.
Set the ViewController's Simulated Size to Freeform and set a very large height. E.g: 1000 and voilà! You can now scroll to see all the stuff and add even more! :)
P.S: Remember to set set Fixed when you are finish to avoid problems!
Just a workaround which helps in Xcode4:
Expand the Objects Panel which resides on the left of the Interface Builder view (there is the tiny arrow at the bottom of the panel).
Drag your UIScrollView from the view hierachy and place it on the top level.
Now you can resize it to access more content (scrolling to that content did not work for me).
When you are done adding child views to the scrollview, you need to resize it back to be smaller or the same size as the parent view.
After your changes you would need to put back the scroll view where it belongs in your hierachy
I typically do the following when I want to (have to) build a long scrolling screen:
Set the size of the View Controller to Freeform
Set the height of the top level View to something very large
Arrange all the controls that I want on the View
Select all the controls
Select Editor->Embed In->Scroll View
Set the size of the View Controller back to normal (typically Inferred)
Well, there are a few different things you can do. There is a list of items in your view you can open on the left of the workspace by clicking the button that looks like a little play button on the toolbar. Double clicking any item selects it so you can use the arrow keys.
The best option is to use the layout panel (typically on the right) and enter position values manualy. Sometimes I will use this to move my scrollview up to where I can see where I'm working then move it back.
I found a solution although you have to use a Table view controller. If you define the table as static, the scroll works in interface builder when the table is bigger than the windows size. Moreover, a standard view can be added to the top and bottom of the table, these views are scrollable as well. The scroll is made once the controller is selected. I hope you find this trick useful.
I know this isn't exactly what you were looking for, but I always just drag the scroll view out of the view controller onto the "pasteboard" where you can resize it at will and see the whole thing.
Once I make my edits I simply resize it to fit it's allotted space in my view and place it back in the view controller.
set the root view to freeform and ~1000 pt height, go through the child views and set them to this height as well(including scroll view), in the viewdidload method set the height to the appropriate size.