Skip to content

Instantly share code, notes, and snippets.

@hudinwal
Created August 16, 2016 18:48
Show Gist options
  • Save hudinwal/1e6e06894013d2475e3d0416b34d7147 to your computer and use it in GitHub Desktop.
Save hudinwal/1e6e06894013d2475e3d0416b34d7147 to your computer and use it in GitHub Desktop.
//
// ViewController.swift
// PullDownSample
//
// Created by Dinesh Kumar on 15/08/16.
// Copyright © 2016 Organization. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
lazy var primaryLabel : UILabel = {
let primaryLabel = UILabel()
primaryLabel.text = "Product"
primaryLabel.font = UIFont.systemFontOfSize(18.0, weight: UIFontWeightMedium)
primaryLabel.textColor = UIColor.init(white: 0.1, alpha: 1.0)
primaryLabel.backgroundColor = UIColor.init(white: 0.9, alpha: 0.5)
primaryLabel.translatesAutoresizingMaskIntoConstraints = false
primaryLabel.setContentHuggingPriority(UILayoutPriorityDefaultLow, forAxis:.Horizontal)
primaryLabel.setContentCompressionResistancePriority(UILayoutPriorityDefaultLow, forAxis: .Horizontal)
return primaryLabel
}()
func addPrimaryLabelWithConstraints() {
self.view.addSubview(primaryLabel)
primaryLabel.topAnchor.constraintEqualToAnchor(self.view.layoutMarginsGuide.topAnchor, constant: 30.0).active = true
primaryLabel.leadingAnchor.constraintEqualToAnchor(self.view.layoutMarginsGuide.leadingAnchor, constant: 0.0).active = true
}
lazy var secondaryLabel : UILabel = {
let secondaryLabel = UILabel()
secondaryLabel.text = "Product_Name"
secondaryLabel.font = UIFont.systemFontOfSize(18.0, weight: UIFontWeightThin)
secondaryLabel.textColor = UIColor.init(white: 0.4, alpha: 1.0)
secondaryLabel.backgroundColor = UIColor.init(white: 0.9, alpha: 0.5)
secondaryLabel.translatesAutoresizingMaskIntoConstraints = false
secondaryLabel.setContentHuggingPriority(UILayoutPriorityDefaultHigh, forAxis:.Horizontal)
secondaryLabel.setContentCompressionResistancePriority(UILayoutPriorityDefaultHigh, forAxis: .Horizontal)
return secondaryLabel
}()
func addSecondaryLabelWithConstraints() {
self.view.addSubview(secondaryLabel)
secondaryLabel.topAnchor.constraintEqualToAnchor(self.view.layoutMarginsGuide.topAnchor, constant: 30.0).active = true
secondaryLabel.trailingAnchor.constraintEqualToAnchor(self.view.layoutMarginsGuide.trailingAnchor, constant: 0.0).active = true
}
func addConstraintsBetweenLabels() {
secondaryLabel.leadingAnchor.constraintEqualToAnchor(primaryLabel.trailingAnchor, constant: 8.0).active = true
}
func updateProductName(name productName: String) {
secondaryLabel.text = productName
}
override func viewDidLoad() {
super.viewDidLoad()
addPrimaryLabelWithConstraints()
addSecondaryLabelWithConstraints()
addConstraintsBetweenLabels()
updateProductName(name: "Apple Macbook Pro - Retina")
}
override func prefersStatusBarHidden() -> Bool {
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment