vds_ios/VDS/Components/Label/Attributes/ToolTipLabelAttribute.swift
Matt Bruce 1d3431da2c updated frame
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-04-14 16:28:05 -05:00

59 lines
1.9 KiB
Swift

//
// ToolTipLabelAttribute.swift
// VDS
//
// Created by Matt Bruce on 10/4/22.
//
import Foundation
import UIKit
import Combine
public struct ToolTipLabelAttribute: ActionLabelAttributeModel {
public var id = UUID()
public var accessibleText: String? = "Tool Tip"
public var action: PassthroughSubject<Void, Never>
public var location: Int
public var length: Int
public var tintColor: UIColor
public var lineHeight: CGFloat
public var size: Tooltip.Size
public func setAttribute(on attributedString: NSMutableAttributedString) {
var size = size.dimensions.height
var yPos = (lineHeight - size) / 2
print("tooltip yPos: \(yPos)")
if yPos < 0 {
yPos = 0
size = lineHeight
}
let image = ImageLabelAttribute(location: location,
length: length,
imageName: "info",
frame: .init(x: 0, y: yPos, width: size, height: size),
tintColor: tintColor)
image.setAttribute(on: attributedString)
}
public init(action: PassthroughSubject<Void, Never> = .init(), location: Int, length: Int, tintColor: UIColor = .black, accessibleText: String? = nil, size: Tooltip.Size = .medium, lineHeight: CGFloat = 0.0){
self.action = action
self.location = location
self.length = length
self.tintColor = tintColor
self.accessibleText = accessibleText
self.lineHeight = lineHeight
self.size = size
}
public static func == (lhs: ToolTipLabelAttribute, rhs: ToolTipLabelAttribute) -> Bool {
lhs.isEqual(rhs)
}
public func isEqual(_ equatable: ToolTipLabelAttribute) -> Bool {
return id == equatable.id && range == equatable.range
}
}