Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.