-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileNameView.swift
More file actions
68 lines (50 loc) · 2.72 KB
/
ProfileNameView.swift
File metadata and controls
68 lines (50 loc) · 2.72 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
64
65
66
67
68
//
// ProfileNameView.swift
// Cluster
//
// Created by Michael Fellows on 3/2/16.
// Copyright © 2016 ImagineME. All rights reserved.
//
import Foundation
class ProfileNameView : UIView {
var avatarImageView: PFImageView = PFImageView()
var nameLabel: UILabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
self.translatesAutoresizingMaskIntoConstraints = false
self.backgroundColor = .clearColor()
self.avatarImageView.clipsToBounds = true
self.avatarImageView.translatesAutoresizingMaskIntoConstraints = false
self.nameLabel.translatesAutoresizingMaskIntoConstraints = false
self.nameLabel.font = UIFont.systemFontOfSize(17) //UIFont(name: "BondoluoPeek", size: 18)
self.nameLabel.textColor = .whiteColor()
self.addSubview(self.avatarImageView)
self.addSubview(self.nameLabel)
let views = ["avatarImageView" : self.avatarImageView,
"nameLabel" : self.nameLabel]
let spacing = 5.0
let height = Double.init(self.frame.size.height)
let imageDiameter = height - (2 * spacing)
let metrics = ["imageDiameter": imageDiameter, "spacing": spacing] as [String : AnyObject]
// Set the corner radius of the avatar view
self.avatarImageView.layer.cornerRadius = CGFloat(imageDiameter / 2.0)
let hConstraint = NSLayoutConstraint.constraintsWithVisualFormat("H:|[avatarImageView(==imageDiameter)]-(spacing)-[nameLabel]-(spacing)-|",
options: NSLayoutFormatOptions(rawValue: 0),
metrics:metrics, views: views)
let avatarY = NSLayoutConstraint.constraintsWithVisualFormat("V:|-(spacing)-[avatarImageView(==imageDiameter)]-(spacing)-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metrics, views: views)
let labelY = NSLayoutConstraint.constraintsWithVisualFormat("V:|-(spacing)-[nameLabel]-(spacing)-|", options:NSLayoutFormatOptions(rawValue: 0), metrics: metrics, views: views)
self.addConstraints(hConstraint)
self.addConstraints(avatarY)
self.addConstraints(labelY)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
func layoutForUser(user: PFUser?) {
if let user = user {
self.nameLabel.text = user.objectForKey("firstName") as? String
self.avatarImageView.file = user.objectForKey("avatarThumbnail") as? PFFile
self.avatarImageView.loadInBackground()
}
}
}