-
Notifications
You must be signed in to change notification settings - Fork 0
/
SampleCode.swift
53 lines (42 loc) · 1.64 KB
/
SampleCode.swift
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
//
// SampleCode.swift
// UIKitChain
//
// Created by Malith Kamburapola on 2022-01-16.
//
import UIKit
class SampleViewController: UIViewController {
private var circleView: UIView!
private func createViews() {
//With out UIKitChain
// circleView = UIView()
// circleView.backgroundColor = .green
// circleView.layer.cornerRadius = 50
// circleView.layer.borderColor = UIColor.black.cgColor
// circleView.layer.borderWidth = 1
// circleView.clipsToBounds = true
// circleView.translatesAutoresizingMaskIntoConstraints = false
//With UIKitChain
circleView = UIView().chain.bgColor(.green).cornerRadius(50).clipToBounds(true).border(.black).activeAutoConstrant(false).component
}
private func insertAndLayoutSubviews() {
view.addSubview(circleView)
NSLayoutConstraint.activate([circleView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
circleView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor),
circleView.heightAnchor.constraint(equalToConstant: 100),
circleView.widthAnchor.constraint(equalTo: circleView.heightAnchor)])
}
override func viewDidLoad() {
super.viewDidLoad()
createViews()
insertAndLayoutSubviews()
}
}
//MARK: - ADD MISSING FUNCTIONS OR VARIABLE
extension UIKitChain where Component: UIView {
@discardableResult
func roundView() -> Self {
component.layer.cornerRadius = component.bounds.height/2
return self
}
}