Autolayout not working
yawboafo opened this issue · 7 comments
Applying constrains programatically to this seems not to work
WidthAnchor and HeightAnchor somehow does not affect the view , you will have to set the view width and height using the Frame .
I face the same autolayout problem. Could it be solved?.
the strange thing is that in the example project, if they work. @yawboafo @korantengNanaYaw
I added an example for applying constraints programmatically. It's working without the problems mentioned. Please check the code in file ViewController.swift
, or bellow:
// Example for applying constraints programmatically
func applyNewConstraints() {
// ......
// Add new constraints programmatically
self.stepIndicatorView.widthAnchor.constraint(equalToConstant: 263.0).isActive = true
self.stepIndicatorView.heightAnchor.constraint(equalToConstant: 80.0).isActive = true
self.stepIndicatorView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
self.stepIndicatorView.topAnchor.constraint(equalTo: self.view.layoutMarginsGuide.topAnchor, constant:30.0).isActive = true
self.scrollView.topAnchor.constraint(equalTo: self.stepIndicatorView.bottomAnchor, constant: 8.0).isActive = true
}
The running effect with constraints added programmatically:
Please let know if there is something I missed. @yawboafo,@korantengNanaYaw,@derlysbenito
@chenyun122
Try creating the step Indicator programatically , remove and delete the reference from story board., to reproduce the issue i'm facing
lazy var stepIndicatorView: StepIndicatorView = {
let view = StepIndicatorView()
view.numberOfSteps = 3
view.circleStrokeWidth = 1.5
view.circleRadius = 14
view.lineMargin = 4.0
view.lineStrokeWidth = 2.0
view.displayNumbers = true
view.direction = .leftToRight
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
The fix i used was that i had to define
view.frame.size.width = 300
view.frame.size.height = 100`
i still could not set widthAnchor without defining the frame size
@yawboafo , thanks for the helpful details. The bug is now FIXED with the new version 1.0.8. Please update the lib with pod or source code.
Excellent, I just updated my library to version 1.0.8, and the autolayout works perfectly! thanks for the support @chenyun122 . This library seems great to me.
Thanks it works now !