This repository has been archived by the owner on Feb 17, 2021. It is now read-only.
/
MiniProfileLayout.swift
56 lines (48 loc) · 1.96 KB
/
MiniProfileLayout.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
// Copyright 2016 LinkedIn Corp.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// ANY CHANGES TO THIS FILE SHOULD ALSO BE MADE IN `Documentation/docs/layouts.md`
import UIKit
import LayoutKit
/// A small version of a LinkedIn profile.
open class MiniProfileLayout: InsetLayout<View> {
public init(imageName: String, name: String, headline: String) {
let image = SizeLayout<UIImageView>(
width: 80,
height: 80,
alignment: .center,
config: { imageView in
imageView.image = UIImage(named: imageName)
// Not the most performant way to do a corner radius, but this is just a demo.
imageView.layer.cornerRadius = 40
imageView.layer.masksToBounds = true
}
)
let nameLayout = LabelLayout(text: name, font: UIFont.systemFont(ofSize: 40))
let headlineLayout = LabelLayout(
text: headline,
font: UIFont.systemFont(ofSize: 20),
config: { label in
label.textColor = UIColor.darkGray
}
)
super.init(
insets: UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8),
sublayout: StackLayout(
axis: .horizontal,
spacing: 8,
sublayouts: [
image,
StackLayout(axis: .vertical, spacing: 2, sublayouts: [nameLayout, headlineLayout])
]
),
config: { view in
view.backgroundColor = UIColor.white
}
)
}
}