-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.swift
More file actions
63 lines (51 loc) · 1.93 KB
/
ViewController.swift
File metadata and controls
63 lines (51 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// ViewController.swift
// StackViewWithButtons
//
// Created by Ramala Srinivasulu, Leela on 9/26/18.
// Copyright © 2018 Leela. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var buttonsHolder: UIStackView!
@IBOutlet weak var firstButton: UIButton!
@IBOutlet weak var secondButton: UIButton!
@IBOutlet weak var hideOrShowButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
// Hide second button so that first button should be center aligned with proportional width.
@IBAction func hideSecondButton(_ sender: Any) {
UIView.animate(withDuration: 0.5) {
if self.secondButton.isHidden {
// Unhide Second button
self.secondButton.isHidden = false
self.buttonsHolder.modify(forAxis: .horizontal, alignment: .fill, distribution: .fillEqually)
self.hideOrShowButton.setTitle("Hide", for: .normal)
} else {
// Hide Second button and show in center of the view
self.secondButton.isHidden = true
self.buttonsHolder.modify(forAxis: .vertical, alignment: .center, distribution: .fillProportionally)
self.hideOrShowButton.setTitle("Show", for: .normal)
}
}
}
}
extension UIStackView {
func modify(forAxis axis: NSLayoutConstraint.Axis, alignment: UIStackView.Alignment, distribution: Distribution) {
self.axis = axis
self.distribution = distribution
self.alignment = alignment
}
}
@IBDesignable extension UIButton {
@IBInspectable var cornerRadius: CGFloat {
set {
self.layer.cornerRadius = newValue
}
get {
return self.layer.cornerRadius
}
}
}