Created
January 18, 2017 11:04
-
-
Save mouselangelo/4d8abf2a49cd202773d4e0ba3b0701dd to your computer and use it in GitHub Desktop.
Swift - Avoid magic numbers
This file contains hidden or 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 | |
** | |
All view dimensions used in the app | |
*/ | |
struct Dimens { | |
/** | |
Common dimensions - used across the app | |
*/ | |
struct Common { | |
/** Horizontal Margins from left and right edges of screen */ | |
static let horizontalMargin: CGFloat = 20.0 | |
/** Vertical Margin from top and bottom edges of screen */ | |
static let verticalMargin: CGFloat = 20.0 | |
} | |
/** | |
Text sizes - used across the app | |
*/ | |
struct Text { | |
/** Title font size */ | |
static let title: CGFloat = 18.0 | |
/** Sub-title font size */ | |
static let subTitle: CGFloat = 16.0 | |
/** Body text font size */ | |
static let bodyText: CGFloat = 14.0 | |
} | |
/** | |
Rooms & Profesional Filters views | |
*/ | |
struct FilterView { | |
static let subCategoryLeftMargin: CGFloat = 40.0 | |
static let titleHeight: CGFloat = 36.0; | |
} | |
} | |
// Example usage | |
class FilterViewController: UIViewController { | |
var titleLabel: UILabel! | |
override func viewDidLoad() { | |
titleLabel.font = UIFont.systemFont(ofSize: Dimens.Text.title) | |
titleLabel.bounds.size.height = Dimens.FilterView.titleHeight | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment