Constrain to margin isn't working properly on Xcode - swift

I'm trying to set a constrain of "0" to a UIImageView from the sides (left & right) but when I add the constrain with "Constrain to margin" checked, it pins the image all the way to the edge of the ViewController while it should keep some distance, why is this happening?

I was having the same problem and recently resolved the issue by turning off the safe area. Safe Area Layout is enabled by default. To disable Safe Area Layout in Xcode 9, choose View > Utilities > Show File Inspector and deselect the checkbox for Use Safe Area Layout Guides. This should correct the issue. Good luck, hope it helps.

Check to see if your UIImageView is overlapping or placed past that margin line. If this is the case, the constrain to margin thing doesn't do anything. What I did to fix this was manually move that object so that it was away from the margin line and try again.
This lets you keep the Safe Area.

I found that if the UIView is overlapped with or by another view this issue also happens - for example if you want to put an image up by the side and you also have a full screen camera preview.
The solution for me was to drag the view where I wanted it (i.e. to one side) and then set the constraints and it behaved properly from then on - I did not have to remove the safe view. This is with Xcode 10.1.

Related

How to resize an NSImageView in an NSStackView?

I'm working on a project where I want the following in an NSTableViewCell:
Image
Text
Subtitle text
The NSTableView is in a window which the user can expand or contract. When the window expands and contracts, the text wraps as needed.
That much is working.
When it comes to the image view, I can't get the thing to resize at all. I don't understand how the text automatically wraps, but images don't automatically scale. I've been working on iOS so long that I might have missed something in how stack views differ between iOS and macOS, but I never had this problem in iOS.
I don't have much code because the text wraps properly without any code at all, so instead I posted a minimal project showing the problem on Github:
NSImageTableViewTest
Some things I tried:
I have to set the width/height of the image view, or the text won't wrap. It seems to me that the reason why is that if I keep the image view unbound, the table view starts at the width of the image.
I tried setting the leading and bottom constraints of the image view to no avail.
I tried setting the constraints of the NSStackView, but that doesn't help constrain the frame of the image view.
Question: do I have to change the frame of the image view in code? I did try that, to no avail.
At this point, I'm stumped and I'm sure the fix is something easy that I overlooked.
Thanks.
The image view doesn't shrink because the default Content Compression Resistance Priority is too high. Set the Content Compression Resistance Priority to (a bit lower than) "Low (250)".

Xcode constraints and uiimageview as a background

I am sorry if I am going off topic, this is not a question about code, but I am having troubles with constraints
In my app I use a UIImageView as background, I set the constraint for the image to fit the screen and it works
But after that i have a lot of labels and buttons,and if i add even one constraint to one of these elements,it disappears or goes out of the UIImage
I want to set the UIImageView as background,so all the other elements can be placed on the image using constraints ,how do i do it?
To simplify the process can i group all of my interface elements in some views and then apply the constraints to the view?
I need a good explanation and/or tutorial about this elements, at the moment my interface on iPhone 4 fits ok until the iAd shows up, and on the other iPhones there is a lot of empty space
take a look at this tutorial. Hopefully, it will works.
http://www.raywenderlich.com/83276/beginning-adaptive-layout-tutorial
Try this: with one of you elements, cmd+click (or right-click) on it and drag upward until the background UIImage is highlighted. Release and select 'left'. This sets a pinning constraint to the left side of the background image.
Then cmd+click and drag to the side, and select 'top'. This should pin your element to an intelligible spot; it may still need some sizing help, but at least you will be able to guess where it will show up.

Advanced Auto-Layout in Xcode 6

I've build this view in inferred size in Xcode 6 -
Every button is in an image view. When i run the app it looks terrible.
I know a little bit about auto-layout but i can't make it look good.
Any tips?
I guess the only way to help you is to suggest you grabbing a good auto-layout tutorial. I guess this one is perfect in your case: https://www.youtube.com/watch?v=IwSTXY0awng
Hope you will get a better understanding of using auto-layout.
Nevertheless if you want some immediate tips, here are some. Remember that I can only guess how the appearance should look like on other screen, it all depends on your vision:
1)Set the trailing space and leading space to superview for the blue rectangle. Don't forget to pin it on the top as well
2) Set leading space for YT and FB buttons, the first should be pinned to the blue rectangle while the latter should be pinned to the bottom of subview.
3) Do the analogy with yellow and green one, but set the trailing space instead of leading space
4) Twitter button should be pinned to fb icon and to the bottom of subview

Autolayout and Tableview Headers

I'm trying to recreate the default viewForHeaderInSection only with a button in each header, using autolayout. The crux of my layout is:
#"|-[titleLabel]-4-[refreshButton(==22)]"
This works just fine in both portrait and landscape on my iPhone.
However, when run on an iPad, the 'titleLabel' is too close to the left margin (because the margins are larger on the iPad). I had hoped that |- would use the standard margin to position the label, but it seems not (I guess it just uses a default number of points).
How can I position this label correctly? Do I need to check for iPad vs iPhone and update a constant? Or can I refer to some constant value that represents the margin size?
You should add a new constraint which aligns the left edge of the titleLabel to the left edge of the UITableView. In IB/Storyboard, this is easily done:
Select both objects
Click the alignment button (the first one in this image: )
Click align Left Edges

autoresizingMask not responding properly

I've implemented autoresizing mask in all my the views of my project very successfully. However in the last one, which is the settings and there are a lot of sliders inside tableCells, it seems it doesn't work too well.:
I'm sure I've implemented the thing right
slide.autoresizingMask=UIViewAutoresingFlexibleWidth
for the sliders and flexible left margin for the labels.
I've also implemented table reload when the rotation takes place.
The cells are being reused ok, or at least in portrait mode they work, but when I rotate and go back I got what you see in the picture.
Any ideas on what am I missing?
Thansk in advance!