Skip to content

Instantly share code, notes, and snippets.

@mcmurrym
Last active August 29, 2015 14:21
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 mcmurrym/a365603bdee65c6adf61 to your computer and use it in GitHub Desktop.
Save mcmurrym/a365603bdee65c6adf61 to your computer and use it in GitHub Desktop.
Add Layout margin controls to IB. I hope Apple eventually integrates a layoutMargin attribute control into IB, until then this should do the trick. Just drop it in to your project and it should show up in IB. For iOS 8.0 and up
// UIViewIBLayoutMarginSupport.swift
// Created by Matt McMurry on 5/26/15.
import UIKit
public extension UIView {
@IBInspectable public var leftLayoutMagrin: CGFloat {
set {
var margins = layoutMargins
margins.left = newValue
layoutMargins = margins
}
get {
return layoutMargins.left
}
}
@IBInspectable public var rightLayoutMagrin: CGFloat {
set {
var margins = layoutMargins
margins.right = newValue
layoutMargins = margins
}
get {
return layoutMargins.right
}
}
@IBInspectable public var topLayoutMagrin: CGFloat {
set {
var margins = layoutMargins
margins.top = newValue
layoutMargins = margins
}
get {
return layoutMargins.top
}
}
@IBInspectable public var bottomLayoutMagrin: CGFloat {
set {
var margins = layoutMargins
margins.bottom = newValue
layoutMargins = margins
}
get {
return layoutMargins.bottom
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment