Skip to content

Instantly share code, notes, and snippets.

@3lvis
Last active August 29, 2015 14:23
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/ac3025777708cd91fef1 to your computer and use it in GitHub Desktop.
Save 3lvis/ac3025777708cd91fef1 to your computer and use it in GitHub Desktop.
UITableViewCell Designer
import UIKit
import XCPlayground
class Cell: UITableViewCell {
init(frame: CGRect) {
super.init(style: .Default, reuseIdentifier: "Sample")
self.frame = frame
self.backgroundColor = .redColor()
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
let shouldDisplayLandscapes = false
let cellHeight = 100.0
let margin = 40.0
let generalTopMargin = 30.0
let labelHeight = 30.0
func y(position: Int) -> Double {
return cellHeight * 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: (cellHeight + margin) * viewPortCount))
let iPhone4n5PortraitFrame = CGRect(x: 0.0, y: y(0), width: 320.0, height: cellHeight)
let iPhone6PortraitFrame = CGRect(x: 0.0, y: y(1), width: 375.0, height: cellHeight)
let iPhone6PlusPortraitFrame = CGRect(x: 0.0, y: y(2), width: 414.0, height: cellHeight)
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 iPhone4n5Portrait = Cell(frame: iPhone4n5PortraitFrame)
let iPhone6Portrait = Cell(frame: iPhone6PortraitFrame)
let iPhone6PlusPortrait = Cell(frame: iPhone6PlusPortraitFrame)
let iPhone4Landscape = Cell(frame: iPhone4LandscapeFrame)
let iPhone5Landscape = Cell(frame: iPhone5LandscapeFrame)
let iPhone6Landscape = Cell(frame: iPhone6LandscapeFrame)
let iPhone6PlusLandscape = Cell(frame: iPhone6PlusLandscapeFrame)
//*** Portrait ***//
container.addSubview(iPhone4n5Portrait)
container.addSubview(iPhone6Portrait)
container.addSubview(iPhone6PlusPortrait)
container.addSubview(label(iPhone4n5PortraitFrame, "iPhone 4/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment