Skip to content

Commit

Permalink
Remove solution code from main ViewController.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Hyche committed Aug 6, 2017
1 parent f4be738 commit 68c75d0
Showing 1 changed file with 1 addition and 67 deletions.
68 changes: 1 addition & 67 deletions StackViewSynthesis3/StackViewSynthesis3/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,73 +34,7 @@ class ViewController: UIViewController {
stackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor).isActive = true
stackView.widthAnchor.constraint(equalTo: scrollView.widthAnchor).isActive = true

// Configure the stack view here
stackView.axis = .vertical
stackView.distribution = .fill
stackView.alignment = .fill
stackView.spacing = 4.0

// Add an "Add Item" row to the stack view
let addItemButton = UIButton(frame: .zero)
addItemButton.setTitle("Add Item", for: .normal)
addItemButton.setTitleColor(UIColor.blue, for: .normal)
addItemButton.addTarget(self, action: #selector(addItemButtonTapped(sender:)), for: .touchUpInside)

stackView.addArrangedSubview(addItemButton)
}

@objc private func addItemButtonTapped(sender: UIButton) {
let insertionIndex = stackView.arrangedSubviews.count - 1
let viewToInsert = rowView()
viewToInsert.isHidden = true
stackView.insertArrangedSubview(viewToInsert, at: insertionIndex)

UIView.animate(withDuration: 0.3, animations: {
viewToInsert.isHidden = false
})
}

@objc private func deleteItemButtonTapped(sender: UIButton) {
if let viewToRemove = sender.superview,
stackView.arrangedSubviews.contains(viewToRemove) {
UIView.animate(withDuration: 0.3,
animations: {
viewToRemove.isHidden = true
},
completion: { (finished) in
viewToRemove.removeFromSuperview()
})
}
}

private func rowView() -> UIView {
let rowStackView = UIStackView(frame: .zero)

rowStackView.axis = .horizontal
rowStackView.distribution = .fill
rowStackView.alignment = .firstBaseline
rowStackView.spacing = 8.0

let dateLabel = UILabel(frame: .zero)
dateLabel.text = DateFormatter.localizedString(from: Date(), dateStyle: .none, timeStyle: .short)
dateLabel.font = UIFont.preferredFont(forTextStyle: .body, compatibleWith: traitCollection)
dateLabel.textColor = UIColor.black

let uuidLabel = UILabel(frame: .zero)
uuidLabel.text = UUID().uuidString
uuidLabel.textColor = UIColor.black
uuidLabel.font = UIFont.preferredFont(forTextStyle: .headline, compatibleWith: traitCollection)

let deleteButton = UIButton(frame: .zero)
deleteButton.setTitle("Delete", for: .normal)
deleteButton.setTitleColor(UIColor.blue, for: .normal)
deleteButton.addTarget(self, action: #selector(deleteItemButtonTapped(sender:)), for: .touchUpInside)

rowStackView.addArrangedSubview(dateLabel)
rowStackView.addArrangedSubview(uuidLabel)
rowStackView.addArrangedSubview(deleteButton)

return rowStackView
// Add your code here
}


Expand Down

0 comments on commit 68c75d0

Please sign in to comment.