Skip to content

Instantly share code, notes, and snippets.

@mouselangelo
Created January 18, 2017 11:04
Show Gist options
  • Save mouselangelo/4d8abf2a49cd202773d4e0ba3b0701dd to your computer and use it in GitHub Desktop.
Save mouselangelo/4d8abf2a49cd202773d4e0ba3b0701dd to your computer and use it in GitHub Desktop.
Swift - Avoid magic numbers
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