Last active
August 29, 2015 14:27
-
-
Save ilteris/a5f1cfa89d4e31af6c1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Drawable { | |
var viewLocation: viewLocation { set get } | |
} | |
enum ViewLocation { | |
case Workspace | |
case Choices | |
case Undo | |
} | |
let statementView = StatementView(".Workspace") | |
let statementView = StatementView(".Choices") | |
// Workspace, Choices, Undo are all views. I need to render | |
// statementView instances slightly different based on the views. | |
// Is it a good idea to pass the view enum value to the statement view when I instantiate it? | |
// It does feel super code smell to me. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class StatementView: UIControl, Drawable { | |
var viewLocation:ViewLocation | |
let termView:TermView | |
private func setupView() { | |
termView = TermView() //gotta pass the /viewLocation enum value to TermView now | |
} | |
init(frame: CGRect, item: ViewLocation) { | |
self.viewLocation = item | |
super.init(frame: frame) | |
setupView() | |
} | |
convenience init(item: ViewLocation) { | |
self.init(frame:CGRectZero, item: item) | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class TermView: UIControl, Drawable { | |
var labels = [UILabel]() | |
var item: Term | |
convenience init(item: Term) { | |
self.init(frame:CGRectZero, item: item) | |
} | |
init(frame: CGRect, item: Term) { | |
self.item = item | |
super.init(frame: frame) | |
setupView() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
private func setupView() { | |
let label = UILabel() | |
label.userInteractionEnabled = false | |
label.font = UIFont(name: "FiraSans-Book", size: 18) | |
label.textColor = UIColor.blackColor() | |
label.textAlignment = .Center | |
label.numberOfLines = 1 | |
label.attributedText = NSMutableAttributedString(string: item.value) | |
let attributedString = label.attributedText as! NSMutableAttributedString | |
attributedString.addAttribute(NSKernAttributeName, value: 1.1, range: NSMakeRange(0, attributedString.length)) | |
label.attributedText = attributedString | |
label.translatesAutoresizingMaskIntoConstraints = false | |
addSubview(label) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment