forked from tvidenov/appstore-clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppDetailHeader.swift
109 lines (86 loc) · 3.46 KB
/
AppDetailHeader.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// AppDetailHeader.swift
// AppStore
//
// Created by Tihomir Videnov on 11/12/16.
// Copyright © 2016 Tihomir Videnov. All rights reserved.
//
import UIKit
class AppDetailHeader: BaseCell {
var app: App? {
didSet {
if let imagename = app?.imageName {
imageView.image = UIImage(named: imagename)
}
nameLabel.text = app?.name
if let price = app?.price?.stringValue {
buyButton.setTitle("$\(price)", for: .normal)
}
if let cat = app?.category {
categoryName.text = cat
}
}
}
let imageView: UIImageView = {
let iv = UIImageView()
iv.contentMode = .scaleAspectFill
iv.layer.cornerRadius = 16
iv.layer.masksToBounds = true
return iv
}()
let segmentedControl: UISegmentedControl = {
let sc = UISegmentedControl(items: ["Details","Reviews","Related"])
sc.tintColor = .darkGray
sc.selectedSegmentIndex = 0
return sc
}()
let nameLabel: UILabel = {
let label = UILabel()
label.text = "Test"
label.font = UIFont.systemFont(ofSize: 16)
return label
}()
let categoryName: UILabel = {
let cn = UILabel()
cn.text = "games"
cn.textColor = .darkGray
cn.font = UIFont.systemFont(ofSize: 12)
cn.translatesAutoresizingMaskIntoConstraints = false
return cn
}()
let buyButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("BUY", for: .normal)
button.layer.borderColor = UIColor(red: 0, green: 125/255, blue: 250/255, alpha: 1).cgColor
button.layer.borderWidth = 1
button.layer.cornerRadius = 5
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)
return button
}()
let dividerView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(white: 0.4, alpha: 0.4)
return view
}()
override func setupViews() {
super.setupViews()
// backgroundColor = .cyan
addSubview(imageView)
addSubview(segmentedControl)
addSubview(nameLabel)
addSubview(categoryName)
addSubview(buyButton)
addSubview(dividerView)
addConstraintsWithFormat(format: "H:|-14-[v0(100)]-8-[v1]|", views: imageView, nameLabel)
addConstraintsWithFormat(format: "V:|-14-[v0(100)]", views: imageView)
addConstraintsWithFormat(format: "V:|-14-[v0(20)]", views: nameLabel)
addConstraintsWithFormat(format: "H:|-40-[v0]-40-|", views: segmentedControl)
addConstraintsWithFormat(format: "V:[v0(34)]-8-|", views: segmentedControl)
addConstraintsWithFormat(format: "H:[v0(60)]-14-|", views: buyButton)
addConstraintsWithFormat(format: "V:[v0(30)]-55-|", views: buyButton)
addConstraintsWithFormat(format: "H:|[v0]|", views: dividerView)
addConstraintsWithFormat(format: "V:[v0(0.5)]|", views: dividerView)
addConstraint(NSLayoutConstraint(item: categoryName, attribute: .left, relatedBy: .equal, toItem: imageView, attribute: .right, multiplier: 1, constant: 8))
addConstraint(NSLayoutConstraint(item: categoryName, attribute: .top, relatedBy: .equal, toItem: nameLabel, attribute: .bottom, multiplier: 1, constant: 8))
}
}