Skip to content

Instantly share code, notes, and snippets.

@3lvis
Last active August 29, 2015 14:27
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 3lvis/ab9ccc61057a5fbb8974 to your computer and use it in GitHub Desktop.
Save 3lvis/ab9ccc61057a5fbb8974 to your computer and use it in GitHub Desktop.
View Designer
import UIKit
import XCPlayground
class View: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
self.frame = frame
self.backgroundColor = .blackColor()
let titleLabel = UILabel(frame: CGRect(x: 0, y: 20, width: frame.width, height: 40))
titleLabel.text = "Login"
titleLabel.textColor = UIColor(hex: "006CDD")
titleLabel.textAlignment = .Center
self.addSubview(titleLabel)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
let shouldDisplayLandscapes = false
let margin = 40.0
let generalTopMargin = 30.0
let labelHeight = 30.0
func y(position: Int, previousHeight: Double) -> Double {
return previousHeight * Double(position) + margin * Double(position) + generalTopMargin
}
func label(frame: CGRect, text: String) -> UILabel {
var modifiedFrame = frame
modifiedFrame.origin.y = frame.origin.y - CGFloat(labelHeight)
modifiedFrame.size.height = CGFloat(labelHeight)
let label = UILabel(frame: modifiedFrame)
label.text = text
label.textColor = .grayColor()
return label
}
let viewPortCount = shouldDisplayLandscapes ? 7.0 : 3.0
let maxWidth = shouldDisplayLandscapes ? 736.0 : 414.0
let container = UIView(frame: CGRect(x: 0.0, y: 0.0, width: maxWidth, height: 3000.0))
let iPhone4PortraitFrame = CGRect(x: 0.0, y: y(0, 0), width: 320.0, height: 480.0)
let iPhone5PortraitFrame = CGRect(x: 0.0, y: y(1, 480.0), width: 320.0, height: 568.0)
let iPhone6PortraitFrame = CGRect(x: 0.0, y: y(2, 568.0), width: 375.0, height: 667.0)
let iPhone6PlusPortraitFrame = CGRect(x: 0.0, y: y(3, 667.0), width: 414.0, height: 736.0)
//let iPhone4LandscapeFrame = CGRect(x: 0.0, y: y(3), width: 480.0, height: cellHeight)
//let iPhone5LandscapeFrame = CGRect(x: 0.0, y: y(4), width: 568.0, height: cellHeight)
//let iPhone6LandscapeFrame = CGRect(x: 0.0, y: y(5), width: 667.0, height: cellHeight)
//let iPhone6PlusLandscapeFrame = CGRect(x: 0.0, y: y(6), width: 736.0, height: cellHeight)
let iPhone4Portrait = View(frame: iPhone4PortraitFrame)
let iPhone5Portrait = View(frame: iPhone5PortraitFrame)
let iPhone6Portrait = View(frame: iPhone6PortraitFrame)
let iPhone6PlusPortrait = View(frame: iPhone6PlusPortraitFrame)
//let iPhone4Landscape = View(frame: iPhone4LandscapeFrame)
//let iPhone5Landscape = View(frame: iPhone5LandscapeFrame)
//let iPhone6Landscape = View(frame: iPhone6LandscapeFrame)
//let iPhone6PlusLandscape = View(frame: iPhone6PlusLandscapeFrame)
//*** Portrait ***//
container.addSubview(iPhone4Portrait)
container.addSubview(iPhone5Portrait)
container.addSubview(iPhone6Portrait)
container.addSubview(iPhone6PlusPortrait)
container.addSubview(label(iPhone4PortraitFrame, "iPhone 4 Portrait"))
container.addSubview(label(iPhone5PortraitFrame, "iPhone 5 Portrait"))
container.addSubview(label(iPhone6PortraitFrame, "iPhone 6 Portrait"))
container.addSubview(label(iPhone6PlusPortraitFrame, "iPhone 6 Plus Portrait"))
////*** Landscape ***//
//if shouldDisplayLandscapes {
// container.addSubview(iPhone6Landscape)
// container.addSubview(iPhone4Landscape)
// container.addSubview(iPhone5Landscape)
// container.addSubview(iPhone6PlusLandscape)
//
// container.addSubview(label(iPhone4LandscapeFrame, "iPhone 4 Landscape"))
// container.addSubview(label(iPhone5LandscapeFrame, "iPhone 5 Landscape"))
// container.addSubview(label(iPhone6LandscapeFrame, "iPhone 6 Landscape"))
// container.addSubview(label(iPhone6PlusLandscapeFrame, "iPhone 6 Plus Landscape"))
//}
XCPShowView("Container", container)
extension UIColor {
public convenience init(hex: String) {
let noHasString = hex.stringByReplacingOccurrencesOfString(
"#",
withString: "")
let scanner = NSScanner(string: noHasString)
scanner.charactersToBeSkipped = NSCharacterSet.symbolCharacterSet()
var hexInt: UInt32 = 0
if (scanner.scanHexInt(&hexInt)) {
let red = (hexInt >> 16) & 0xFF
let green = (hexInt >> 8) & 0xFF
let blue = (hexInt) & 0xFF
self.init(
red: CGFloat(red) / 255.0,
green: CGFloat(green) / 255.0,
blue: CGFloat(blue) / 255.0,
alpha: 1.0
)
} else {
self.init(
red: 0.0,
green: 0.0,
blue: 0.0,
alpha: 0.0)
}
}
public class func colorFromHex(hex: String) -> UIColor {
return UIColor(hex: hex)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment