Skip to content

Instantly share code, notes, and snippets.

@kwylez
Last active August 7, 2016 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwylez/cfa16046a4d632e1b0f2ee003a279e09 to your computer and use it in GitHub Desktop.
Save kwylez/cfa16046a4d632e1b0f2ee003a279e09 to your computer and use it in GitHub Desktop.
//
// UserProfileImageView.swift
// Rezli
//
// Created by Cory D. Wiles on 7/27/16.
// Copyright © 2016 Rezli. All rights reserved.
//
import Foundation
private let UserProfileImageViewWidth: CGFloat = 87.5
private let UserProfileImageViewHeight: CGFloat = 87.5
final class UserProfileImageView: UIImageView {
// MARK: Initializers
override init(frame: CGRect) {
super.init(frame: frame)
let defaultImage: UIImage = UIImage(named: "default_profile_cover")!
self.image = defaultImage
self.translatesAutoresizingMaskIntoConstraints = false
self.contentMode = .ScaleAspectFill
self.layer.borderColor = RZLStyleGuideManager.rezliWhite().CGColor
self.layer.borderWidth = 5.0
self.layer.masksToBounds = true
self.setContentHuggingPriority(UILayoutPriorityDefaultHigh, forAxis: .Vertical)
self.setContentHuggingPriority(UILayoutPriorityDefaultHigh, forAxis: .Horizontal)
self.setContentCompressionResistancePriority(UILayoutPriorityDefaultHigh, forAxis: .Vertical)
self.setContentCompressionResistancePriority(UILayoutPriorityDefaultHigh, forAxis: .Horizontal)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
convenience init() {
self.init(frame: CGRectZero)
}
// MARK: Overrides
override func layoutSubviews() {
super.layoutSubviews()
self.bounds = CGRect(x: 0,
y: 0,
width: self.intrinsicContentSize().width,
height: self.intrinsicContentSize().height)
self.layer.cornerRadius = self.bounds.size.width / 2
super.layoutSubviews()
}
override func intrinsicContentSize() -> CGSize {
return CGSizeMake(UserProfileImageViewWidth, UserProfileImageViewHeight)
}
}
/// SNIPPET OF IMPLEMENTATION
/// ScrollView
self.view.rezli_pinAllEdgesOfSubview(self.scrollView)
/// Header View
self.headerLabel.leftAnchor.constraintEqualToAnchor(self.scrollView.contentView.leftAnchor).active = true
self.headerLabel.rightAnchor.constraintEqualToAnchor(self.scrollView.contentView.rightAnchor).active = true
self.headerLabel.topAnchor.constraintEqualToAnchor(self.scrollView.contentView.topAnchor, constant: HeadingSpacing).active = true
/// Upload Avatar Label
self.uploadAvatarHeaderLabel.leftAnchor.constraintEqualToAnchor(margins.leftAnchor).active = true
self.uploadAvatarHeaderLabel.topAnchor.constraintEqualToAnchor(self.headerLabel.bottomAnchor, constant: HeadingSpacing).active = true
self.uploadAvatarHeaderLabel.rightAnchor.constraintEqualToAnchor(margins.rightAnchor).active = true
/// Profile Image
self.profileImageView.leftAnchor.constraintEqualToAnchor(self.uploadAvatarHeaderLabel.leftAnchor).active = true
self.profileImageView.topAnchor.constraintEqualToAnchor(self.uploadAvatarHeaderLabel.bottomAnchor, constant: DefaultOffset).active = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment