Skip to content

Commit

Permalink
add properties for setting bottom and trailing spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth-KT committed Dec 3, 2016
1 parent 5ff3bf7 commit 76401a3
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions Source/ActionButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@ public class ActionButton: NSObject {
}
}

public var bottomSpacing: CGFloat {
get {
return bottomSpacingConstraints.first!.constant
}
set {
bottomSpacingConstraints.first!.constant = newValue
self.parentView.updateConstraintsIfNeeded()
self.parentView.layoutIfNeeded()
}
}

public var trailingSpacing: CGFloat {
get {
return trailingSpacingConstraints.first!.constant
}
set {
trailingSpacingConstraints.first!.constant = newValue
self.parentView.updateConstraintsIfNeeded()
self.parentView.layoutIfNeeded()
}
}

/// The button's background color : set default color
public var backgroundColorSelected: UIColor = UIColor(red: 238.0/255.0, green: 130.0/255.0, blue: 34.0/255.0, alpha:1.0)

Expand Down Expand Up @@ -140,11 +162,11 @@ public class ActionButton: NSObject {
let height = NSLayoutConstraint.constraintsWithVisualFormat("V:[floatButton(\(floatButtonRadius))]", options: NSLayoutFormatOptions.AlignAllCenterX, metrics: nil, views: views)
self.floatButton.addConstraints(width)
self.floatButton.addConstraints(height)
let trailingSpacing = NSLayoutConstraint.constraintsWithVisualFormat("V:[floatButton]-15-|", options: NSLayoutFormatOptions.AlignAllCenterX, metrics: nil, views: views)
let bottomSpacing = NSLayoutConstraint.constraintsWithVisualFormat("H:[floatButton]-15-|", options: NSLayoutFormatOptions.AlignAllCenterX, metrics: nil, views: views)
self.parentView.addConstraints(trailingSpacing)
self.parentView.addConstraints(bottomSpacing)

self.bottomSpacingConstraints = NSLayoutConstraint.constraintsWithVisualFormat("V:[floatButton]-15-|", options: NSLayoutFormatOptions.AlignAllCenterX, metrics: nil, views: views)
self.trailingSpacingConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:[floatButton]-15-|", options: NSLayoutFormatOptions.AlignAllCenterX, metrics: nil, views: views)
self.parentView.addConstraints(trailingSpacingConstraints)
self.parentView.addConstraints(bottomSpacingConstraints)
}

//MARK: - Button Actions Methods
Expand Down

0 comments on commit 76401a3

Please sign in to comment.