Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add tzstackview on scrollview. #66

Open
Sahilberi opened this issue Feb 8, 2016 · 0 comments
Open

how to add tzstackview on scrollview. #66

Sahilberi opened this issue Feb 8, 2016 · 0 comments

Comments

@Sahilberi
Copy link

Hi,
i want to use tzstackview on scrollview to add dynamic content .when i try to add multiple contents on
tzstackview it gives them equal heights. i'm adding tzstackview on scrollview

var tzStackView: TZStackView!

override func viewDidLoad() {
super.viewDidLoad()
tzStackView = TZStackView(arrangedSubviews: createViews())
// tzStackView.backgroundColor = UIColor.redColor()
tzStackView.translatesAutoresizingMaskIntoConstraints = false
tzStackView.axis = .Vertical
tzStackView.distribution = .Fill
tzStackView.alignment = .Fill
tzStackView.spacing = 15

  self.scrollView.contentSize = CGSizeMake(self.view.bounds.size.width,      self.view.bounds.size.height * 2);

self.scrollView.addSubview(tzStackView)

let horizontalConstraint = NSLayoutConstraint(item: tzStackView, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self.scrollView, attribute: NSLayoutAttribute.Trailing, multiplier: 1, constant: 0)

self.view.addConstraint(horizontalConstraint)

let verticalConstraint = NSLayoutConstraint(item: tzStackView, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self.scrollView, attribute: NSLayoutAttribute.Leading, multiplier: 1, constant: 0)
view.addConstraint(verticalConstraint)

let bottom = NSLayoutConstraint(item: tzStackView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self.scrollView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0)
view.addConstraint(bottom)

let top = NSLayoutConstraint(item: tzStackView, attribute: NSLayoutAttribute.Top
  , relatedBy: NSLayoutRelation.Equal, toItem: self.scrollView, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0)
view.addConstraint(top)

}

private func createViews() -> [UIView] {

let textfield = UITextField(frame: CGRect(x: 0, y: 0, width: 500.00, height: 100.00));
let textfield1 = UITextField(frame: CGRect(x: 0, y: 0, width: 500.00, height: 30.00));
let textfield2 = UITextField(frame: CGRect(x: 0, y: 0, width: 500.00, height: 130.00));
let textfield3 = UITextField(frame: CGRect(x: 0, y: 0, width: 500.00, height: 30.00));
let textfield4 = UITextField(frame: CGRect(x: 0, y: 0, width: 500.00, height: 30.00));
let textfield5 = UITextField(frame: CGRect(x: 0, y: 0, width: 500.00, height: 30.00));
let textfield6 = UITextField(frame: CGRect(x: 0, y: 0, width: 500.00, height: 30.00));
let textfield7 = UITextField(frame: CGRect(x: 0, y: 0, width: 500.00, height: 30.00));
let textfield8 = UITextField(frame: CGRect(x: 0, y: 0, width: 500.00, height: 30.00));
let textfield9 = UITextField(frame: CGRect(x: 0, y: 0, width: 500.00, height: 30.00));
let textfield10 = UITextField(frame: CGRect(x: 0, y: 0, width: 500.00, height: 30.00));
let textfield11 = UITextField(frame: CGRect(x: 0, y: 0, width: 500.00, height: 30.00));

textfield1.backgroundColor = UIColor.redColor().colorWithAlphaComponent(0.75)

return [textfield, textfield1, textfield2, textfield3, textfield4,textfield5,textfield6,textfield7,textfield8,textfield9,textfield10,textfield11]

}

i want tzstackview height same as scrollview.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant