Autolayout and Tableview Headers - iphone

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

Related

Constrain to margin isn't working properly on Xcode

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.

Image View - Aligning image in centre on all devices on launchscreen

I'm new to iOS development. I'm trying to add logo on launchscreen in centre. I've a background with gradient colour so I've used a png file and stuck it in the background.
Next is logo which I want to centre for all devices.
I've two part questions
1) Is there anyway I can specify the constraints so that it is applicable to all devices? Example specifying top and bottom constraints in % ?
2) If above is not possible then how do I align logo in centre so that it works on all devices? Do I need to apply constraints separately on all devices?
I tried to set the width and height separately for all devices but it modifies dimensions on other devices. Not sure if this approach will work or I'm doping something wrong?
I'm aware that in worst case that I can just create launchscreens with logo in it as png and stick them for each devices separately which will work. I just wanted to know if it can be done with constraints.
Tx
As you suggested I added constraints to align it in centre horizontally and vertically. It seems to be good on one device but on other it's not. Please see images below.
And then how do I change image size?
One device
2nd device
You do have centerY and centerX constraints.
In storyboard, select the imageView that you have already added to your view. Right-clic drag to the main view (full screen view) in the left panel and choose center horizontally, repeat with center vertically.
You will need to also set the width and height constraints of your logo.
ALTERNATIVELY:
You don't need to clic drag, you can add the center constraints in the "add new alignment constraints" tab.
Finally I manage to solve what I Was looking for thanks to all those who helped. It was good learning period, 2 days in total ;)
Step 1: Align image to centre vertically and horizontally.
Step 2: Scale logo to fill the space. Please follow this video which is bang on point what I was looking for.
http://roadfiresoftware.com/2015/04/how-to-scale-an-image-view-based-on-device-size-with-auto-layout-in-interface-builder/

How to match the image width to screen size in swift ios

Am a beginner in ios. I was trying to make a list of images but i didn't find anything to set the table cell image width same as screen size.
(Am using match_parent in android to achieve this)
Please take a look at the image:
Hope you understand my question.
You have to add imageView to the cell container.
You fix size od the UIImageView and after that you have to adjust autolayout.
Set up autolayout to the left right top and bottom and click add constraints. Look that in every value (0) the the constraint is turned on (red line near the value).
Your image should now stretch horizontally. After that click the "update frames" in selected UIViewImage (Slected Views)

Getting button image to stick to left side swift xcode

Currently trying to add a login with facebook button with xcode 7 beta. However, I have noticed that whenever I readjust the image's width, it seems to leave to left side which is where I want it to stay to the left margin. I am getting this image through the image option when I used the button.
I met the same situation before. In that time, I adjust image inset in storyboard option.
Change image in Edge, and then adjust inset as you like.
But sometimes it doesn't work in my case(ex. the image size is so big). If so, you adjust the original image size.

My button is centered for iPhone 6 and 6 plus, but not for iPhone 5

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