In my app I have this error -
safeAreaLayoutGuide' is only available on iOS 11.0 or newer
In this code the error appears 3 times. Basically in each of the rows where I use safeArea.
NSLayoutConstraint.activate([
stackViewBottomConstrols.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
stackViewBottomConstrols.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
stackViewBottomConstrols.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
stackViewBottomConstrols.heightAnchor.constraint(equalToConstant: 50)
])
Can I just check if IOS 11
is available and run this code and add another code in else
statement with the same code but without safeArea. Would that show the view the same as in the if
statement. If not are there any other solutions ?
Will this code work on devices that doesn't have IOS 11 the same ? -
if #available(iOS 11.0, *) {
NSLayoutConstraint.activate([
stackViewBottomConstrols.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
stackViewBottomConstrols.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
stackViewBottomConstrols.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
stackViewBottomConstrols.heightAnchor.constraint(equalToConstant: 50)
])
} else {
NSLayoutConstraint.activate([
stackViewBottomConstrols.bottomAnchor.constraint(equalTo: view.bottomAnchor),
stackViewBottomConstrols.leadingAnchor.constraint(equalTo: view.leadingAnchor),
stackViewBottomConstrols.trailingAnchor.constraint(equalTo: view.trailingAnchor),
stackViewBottomConstrols.heightAnchor.constraint(equalToConstant: 50)
])
}