Skip to content

Instantly share code, notes, and snippets.

@johndpope-karhoo
Created September 20, 2016 19:56
Show Gist options
  • Select an option

  • Save johndpope-karhoo/cd5149d14bdf51632e952994eb2f7d4c to your computer and use it in GitHub Desktop.

Select an option

Save johndpope-karhoo/cd5149d14bdf51632e952994eb2f7d4c to your computer and use it in GitHub Desktop.

Revisions

  1. johndpope-karhoo created this gist Sep 20, 2016.
    60 changes: 60 additions & 0 deletions SnapKitHelperView.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    import Foundation
    import SnapKit

    let screenWidth = UIScreen.mainScreen().bounds.width

    class SnapKitHelperView:UIView{

    var debugConstraints = false


    override func layoutSubviews() {
    super.layoutSubviews()


    if(debugConstraints){
    for c in self.constraints{
    print("constraints:",c.firstAttribute)
    }
    self.backgroundColor = self.getRandomColor();
    }
    }

    func labelByTag(tag:Int) -> UILabel{
    if let view = self.viewWithTag(tag) as? UILabel{
    return view;
    }else{
    print("FATAL missing label by tag ",tag)
    fatalError()
    }
    return UILabel()
    }
    func viewByTag(tag:Int) -> UIView{
    if let view = self.viewWithTag(tag){
    return view;
    }else{
    print("FATAL missing view by tag ",tag)
    fatalError()
    }
    return UIView()
    }
    func imageViewByTag(tag:Int) -> UIImageView{
    if let view = self.viewWithTag(tag) as? UIImageView{
    return view;
    }else{
    print("FATAL missing image by tag ",tag)
    fatalError()
    }
    return UIImageView()
    }

    func getRandomColor() -> UIColor{
    let randomGreen:CGFloat = CGFloat(drand48())
    let randomBlue:CGFloat = CGFloat(drand48())
    return UIColor(red: 1, green: randomGreen, blue: randomBlue, alpha: 1.0)
    }


    }