Code standard change. Removed legacy-like methods.

This commit is contained in:
Robinson, Blake 2019-12-03 15:21:45 -05:00
parent 988e30daa9
commit 1d647ec662

View File

@ -10,7 +10,7 @@ import UIKit
@objcMembers open class Link: MFCustomButton {
lazy var sizeObject:MFSizeObject? = {
lazy var sizeObject: MFSizeObject? = {
return MFSizeObject(standardSize: 30, standardiPadPortraitSize: 36, iPadProLandscapeSize: 42)
}()
@ -24,6 +24,12 @@ import UIKit
self.setupView()
}
public convenience init(width:CGFloat) {
self.init()
self.setupView()
self.updateView(width)
}
open override func draw(_ rect: CGRect) {
guard let textRect = self.titleLabel?.frame else { return }
@ -44,37 +50,6 @@ import UIKit
contextRef?.closePath()
contextRef?.drawPath(using: .stroke)
}
public static func link() -> Link {
return Link.link(nil, constrainHeight: true, width: CGFloat.leastNormalMagnitude)
}
public static func link(_ button: UIButton?, constrainHeight: Bool, width:CGFloat) -> Link {
let link = linkHelper(button)
//Adds the height constraint.
if let constant = link.sizeObject?.standardSize,
constrainHeight {
let heightConstraint = NSLayoutConstraint(item: link as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: constant)
link.addConstraint(heightConstraint)
heightConstraint.isActive = true
link.heightConstraint = heightConstraint
} else {
link.setContentHuggingPriority(.required, for: .vertical)
}
link.updateView(width)
return link
}
public static func linkHelper(_ button: UIButton?) -> Link {
guard let unwrappedButton = button else { return Link(type:.custom) }
guard let link = unwrappedButton as? Link else { return Link(type:.custom) }
return link
}
}
extension Link: MVMCoreViewProtocol {
@ -105,6 +80,15 @@ extension Link: MVMCoreViewProtocol {
// left alignment by default
self.titleLabel?.textAlignment = .left
self.contentHorizontalAlignment = .left
if let constant = self.sizeObject?.standardSize {
let heightConstraint = NSLayoutConstraint(item: self as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: constant)
self.addConstraint(heightConstraint)
heightConstraint.isActive = true
self.heightConstraint = heightConstraint
}
}
}