updated width
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
4e49a55d7d
commit
e72c751842
@ -76,14 +76,14 @@ open class TileContainer: Control {
|
||||
|
||||
public var imageFallbackColor: Surface = .light { didSet{ didChange() } }
|
||||
|
||||
private var _width: CGFloat = 100
|
||||
public var width: CGFloat {
|
||||
private var _width: CGFloat?
|
||||
public var width: CGFloat? {
|
||||
get { return _width }
|
||||
set {
|
||||
if newValue > 100 {
|
||||
if let newValue, newValue > 100 {
|
||||
_width = newValue
|
||||
} else {
|
||||
_width = 100
|
||||
_width = nil
|
||||
}
|
||||
didChange()
|
||||
}
|
||||
@ -152,14 +152,12 @@ open class TileContainer: Control {
|
||||
addSubview(containerView)
|
||||
addSubview(highlightView)
|
||||
|
||||
widthConstraint = widthAnchor.constraint(equalToConstant: width)
|
||||
widthConstraint?.isActive = true
|
||||
widthConstraint = widthAnchor.constraint(equalToConstant: 0)
|
||||
|
||||
heightGreaterThanConstraint = heightAnchor.constraint(greaterThanOrEqualToConstant: 44.0)
|
||||
heightGreaterThanConstraint?.isActive = false
|
||||
|
||||
heightConstraint = heightAnchor.constraint(equalToConstant: width)
|
||||
heightConstraint?.isActive = true
|
||||
heightConstraint = heightAnchor.constraint(equalToConstant: 0)
|
||||
|
||||
backgroundImageView.pinToSuperView()
|
||||
backgroundImageView.isUserInteractionEnabled = false
|
||||
@ -219,7 +217,7 @@ open class TileContainer: Control {
|
||||
//--------------------------------------------------
|
||||
// MARK: - State
|
||||
//--------------------------------------------------
|
||||
var ratioSize: CGSize {
|
||||
private func ratioSize(for width: CGFloat) -> CGSize {
|
||||
var height: CGFloat = width
|
||||
|
||||
switch aspectRatio {
|
||||
@ -272,21 +270,27 @@ open class TileContainer: Control {
|
||||
containerBottomConstraint?.constant = -padding
|
||||
containerTrailingConstraint?.constant = -padding
|
||||
|
||||
if aspectRatio == .none && height == nil{
|
||||
if let width, aspectRatio == .none && height == nil{
|
||||
widthConstraint?.constant = width
|
||||
widthConstraint?.isActive = true
|
||||
heightConstraint?.isActive = false
|
||||
heightGreaterThanConstraint?.isActive = true
|
||||
} else if let height {
|
||||
} else if let height, let width {
|
||||
widthConstraint?.constant = width
|
||||
heightConstraint?.constant = height
|
||||
heightConstraint?.isActive = true
|
||||
widthConstraint?.isActive = true
|
||||
heightGreaterThanConstraint?.isActive = false
|
||||
} else {
|
||||
let size = ratioSize
|
||||
} else if let width {
|
||||
let size = ratioSize(for: width)
|
||||
widthConstraint?.constant = size.width
|
||||
heightConstraint?.constant = size.height
|
||||
widthConstraint?.isActive = true
|
||||
heightConstraint?.isActive = true
|
||||
heightGreaterThanConstraint?.isActive = false
|
||||
} else {
|
||||
widthConstraint?.isActive = false
|
||||
heightConstraint?.isActive = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -137,7 +137,7 @@ open class Tilet: TileContainer {
|
||||
open var textWidth: CGFloat? {
|
||||
get { _textWidth }
|
||||
set {
|
||||
if let newValue, newValue > 44.0 && newValue <= width {
|
||||
if let newValue, newValue > 44.0 {
|
||||
_textWidth = newValue
|
||||
if _textPercentage != nil {
|
||||
_textPercentage = nil
|
||||
|
||||
Loading…
Reference in New Issue
Block a user