Skip to content

Instantly share code, notes, and snippets.

@alonecuzzo
Created January 23, 2016 00:17
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 alonecuzzo/16933d829b8325885852 to your computer and use it in GitHub Desktop.
Save alonecuzzo/16933d829b8325885852 to your computer and use it in GitHub Desktop.
Style with extensions
//
// ViewController.swift
// Styles
//
// Created by Jabari Bell on 1/22/16.
// Copyright © 2016 Jabari Bell. All rights reserved.
//
import UIKit
protocol BorderStyleable {
var borderWidth: CGFloat { get }
var borderColor: UIColor { get }
}
enum BorderStyle: BorderStyleable {
case Default
var borderWidth: CGFloat {
switch self {
case .Default:
return 1.0
}
}
var borderColor: UIColor {
switch self {
case .Default:
return UIColor.redColor()
}
}
}
protocol BorderStyled {
var borderStyle: BorderStyle { get }
}
extension BorderStyled {
var borderStyle: BorderStyle {
return .Default
}
}
class MyView: UIView {}
extension MyView: BorderStyled {
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment