Xcode margins strange behavior - ios

I have table view cell like this in a xib file:
On iOS 8 it looks as I want, but on iOS 7 the image view on left side and view on the right side look like this:
I know about iOS 8 margins and I have made constraints without the "Constraint to margins" option.
How can I make iOS 7 table view cell similar to iOS 8?

You didn't show all the constraints. Here is an excellent auto-layout tableview sample
which will walk you through the iOS Size Classes or just refer this tutorial.

Related

iOS - Safe Area Layout not work on iOS 9 and iOS 10

Here is the constraints:
It works fine on iOS11, but doesn't work on iOS9 and iOS 10.
You can download the example over here.
Note: The UISwitch must be added to the RedView and use the Safe Area Layout.
https://developer.apple.com/documentation/uikit/uiview/2891102-safearealayoutguide
safeAreaLayoutGuide is introduced in iOS 11. No wonder it doesn't work in iOS 9 and 10.
For older versions, consider using layoutMargins property instead.
let window = UIApplication.shared.keyWindow
let topPadding = window?.layoutMargins
are you trying to achieve this? (ios10 on the left and ios 11 on the right)
If yes, you can do next:
remove safe area from red view
set top constraint of UISwitch to the safe area of the view of view controller but not to the top of the red view.
I checked your code and found top constraint of your Red View is not correct. Your Red View should align top from Safe Area instead of superview.
In my case, setting edgesForExtendedLayout to an empty array for iOS 10 had the desired effect.
Full answer here: https://stackoverflow.com/a/51247890/3885491
If you're using storyboards then it would work because Storyboard is backward-compatible. Bare in mind that storyboards hides the difference in the actual code and not good for deep understanding...
If you're doing it programmatically then:
See Safe Area Layout Guide Tutorial
. SafeArea is available in iOS 11 only. For non-iOS 11 you must use topLayoutGuide.bottomAnchor.
For more see On iOS, what are the differences between margins, edge insets, content insets, alignment rects, layout margins, anchors…?

How can I create an UITableView for an Universal App using Xcode 8.3

I am trying to build an universal app which includes a UITableView but for some reason It shows in a different size even after reseting to suggested constraints. I have also tried to pin top, left, right, and bottom but no luck at all. It only works when I use a UITableViewController but I am thinking of using a ViewController and include a Table View inside. Does anybody knows why Auto layout isn't working for me?
Here is the screenshot of how it looks in a new project with different devices!
Just add a prototype cell and the view will look rite in the Xcode interface builder - By adding all those constraints the xcode tableview doesn't look rite but it will work rite when you add a prototype cell to it. I think its a bug of Xcode interface builder that the grey area looks smaller but cells are extended.
You should set Leading, Top, Trailing, Bottom constraints with the view of your UIViewController. Just like this:

Custom UITableViewController cells won't auto allign

I have some custom cells in a UITableViewController that I've used constraints to set a label to align to the left margin with a a trailing space of 8 and a switch to align to the right margin, also with a trailing space of 8. This looks great on iPhone, but it does not align properly on iPad. Here's what it looks like.
iPhone:
iPad:
How do you set the margin to automatically change based on the screen size so it doesn't look so weird on iPad?
Absolutely nothing I tried would fix this. It turns out that there must be some bug in iOS9/Xcode 7, because I was only able to fix the issue by downgrading my devices to iOS 8 and Xcode to Xcode 6.

iOS 7 keep buttons at bottom in 3.5inch and 4inch

I haven't done iOS development in a while (since Xcode 4 and iOS 5). And I have a very noobish question:
How can I keep buttons at the bottom of a storyboard viewcontroller on both 3.5inch and 4 inch devices? Previously I could use 'origin' or something similar in the right side panel.
A quick solution, especially if you don't need to deal with rotation of elements much is to add some basic auto layout constraints to your view.
Once you have your button set in place in your view where you want it to stay in the view, select your View in the Storyboard and then from the Menu Select Editor -> Resolve Auto Layout Constraints -> Add Missing Constraints in View.
Simply doing that will give you what you want. Make sure you have auto layout enabled for your storyboard.
set autoresizing mask as shown in image to keep button at buttom in both 3.5 and 4.
i think you are using autolayout so apply first approach
with AutoLayout. add constrains for your widgets
without AutoLayout

Auto Layout views inoperable in iOS 6

I'm using Auto Layout for an iPhone app to place a button footer bar at the bottom of the screen on both 3.5" and 4" iPhones. The bar is a UIView containing two UIButtons and a UIImageView.
I have a Vertical Space Constraint pinning the bottom space to the superview.
(Editor -> Pin -> Bottom Space to Superview)
It has an Equal relationship. Constant is 60, Standard is NO, Priority is 1000, and Placeholder is NO.
In iOS 7 it works exactly as expected. In iOS 6, it does not. The bar is not a consistent distance from the bottom when I switch between that view controller and its neighbors, and the buttons frequently do not work (they don't even highlight when I tap them). This is all in the simulator, I haven't tried hardware yet. The app is a legacy app, so all of the layout work is in xib files, not storyboards.
Do I need to do something different in iOS 6 to get Auto Layout to work? From what I read, it should be fully compatible with 6 & 7.
Some more information is needed to really get to the heart of the matter. Specifically how auto layout is being used to attach the bar to the bottom.
One thing that gets me over and over though, is remembering to set the translatesAutoResizingMasksIntoConstraints property to false on view(s) that utilize constraints.
Be sure to check the log output while debugging as that will indicate if you have any ambiguous or unsatisfiable constraints. At design time, XCode 4 IB will attempt to add any constraints that you are missing for you. XCode 5 IB will only tell you what you are missing and then at runtime try to add any missing constraints if it can.

Resources