udpated tooltip attribute
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
2bbe71e106
commit
8ed2506580
@ -14,19 +14,20 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable
|
|||||||
public var id = UUID()
|
public var id = UUID()
|
||||||
public var action = PassthroughSubject<Void, Never>()
|
public var action = PassthroughSubject<Void, Never>()
|
||||||
private var subscriber: AnyCancellable?
|
private var subscriber: AnyCancellable?
|
||||||
|
private var size: Tooltip.Size = .small
|
||||||
public var location: Int = 0
|
public var location: Int = 0
|
||||||
public var length: Int = 3
|
public var length: Int = 3
|
||||||
public var surface: Surface = .light
|
public var surface: Surface = .light
|
||||||
public var accessibleText: String? = "Tool Tip"
|
public var accessibleText: String? = "Tool Tip"
|
||||||
public var closeButtonText: String = "Close"
|
public var closeButtonText: String = "Close"
|
||||||
public var size: Tooltip.Size = .medium
|
|
||||||
public var title: String
|
public var title: String
|
||||||
public var content: String
|
public var content: String
|
||||||
|
|
||||||
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
||||||
//update the location
|
//update the location
|
||||||
location = attributedString.string.count
|
location = attributedString.string.count - 1
|
||||||
|
|
||||||
|
//set the default color off surface for text
|
||||||
var imageTintColor: UIColor = surface == .light ? VDSColor.elementsPrimaryOnlight : VDSColor.elementsPrimaryOndark
|
var imageTintColor: UIColor = surface == .light ? VDSColor.elementsPrimaryOnlight : VDSColor.elementsPrimaryOndark
|
||||||
|
|
||||||
//see if you can get the current textColor
|
//see if you can get the current textColor
|
||||||
@ -34,45 +35,50 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable
|
|||||||
if let textColor = attributedString.attribute(.foregroundColor, at: 0, effectiveRange: &originalRange) as? UIColor {
|
if let textColor = attributedString.attribute(.foregroundColor, at: 0, effectiveRange: &originalRange) as? UIColor {
|
||||||
imageTintColor = textColor
|
imageTintColor = textColor
|
||||||
}
|
}
|
||||||
|
|
||||||
//create the space in the attirbuted String for the tooltip image and click action
|
|
||||||
let spaceForTooltip = String(repeating: " ", count: length)
|
|
||||||
|
|
||||||
//find the middle of the space
|
|
||||||
let middle = (length/2)
|
|
||||||
|
|
||||||
//add the space to the attributed string
|
var frame = CGRect.zero
|
||||||
attributedString.insert(NSAttributedString(string: spaceForTooltip), at: location)
|
if let font = attributedString.attribute(.font, at: 0, effectiveRange: &originalRange) as? UIFont {
|
||||||
|
switch font.pointSize {
|
||||||
|
case 15..<25:
|
||||||
|
size = .medium
|
||||||
|
frame = CGRect(x: 0, y: -1, width: size.value.dimensions.width * 0.80, height: size.value.dimensions.height * 0.80)
|
||||||
|
case 0..<14:
|
||||||
|
size = .small
|
||||||
|
frame = CGRect(x: 0, y: -1, width: size.value.dimensions.width * 0.80 , height: size.value.dimensions.height * 0.80)
|
||||||
|
default:
|
||||||
|
size = .medium
|
||||||
|
frame = CGRect(x: 0, y: -1, width: size.value.dimensions.width, height: size.value.dimensions.height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//create the frame in which to hold the icon
|
//create the frame in which to hold the icon
|
||||||
let frame = CGRect(x: 0, y: 0, width: size.value.dimensions.width, height: size.value.dimensions.width)
|
let spacerframe = CGRect(x: 0, y: 0, width: VDSLayout.Spacing.space1X.value, height: size.value.dimensions.height)
|
||||||
|
|
||||||
//create the image icon and match the color of the text
|
//create the image icon and match the color of the text
|
||||||
let tooltipAttribute = ImageLabelAttribute(location: location + middle,
|
let tooltipAttribute = ImageLabelAttribute(location: location,
|
||||||
length: 1,
|
|
||||||
imageName: "info",
|
imageName: "info",
|
||||||
frame: frame,
|
frame: frame,
|
||||||
tintColor: imageTintColor)
|
tintColor: imageTintColor)
|
||||||
|
|
||||||
//create the action for the tooltip click
|
let spacerAttribute = ImageLabelAttribute(location: location,
|
||||||
let tooltipAction = ActionLabelAttribute(location: location - middle,
|
imageName: "info",
|
||||||
length: length + middle,
|
frame: spacerframe,
|
||||||
shouldUnderline: false,
|
tintColor: .clear)
|
||||||
action: action)
|
|
||||||
|
|
||||||
//apply the attribtes to the current attributedString
|
guard let tooltip = try? tooltipAttribute.getAttachment(),
|
||||||
tooltipAttribute.setAttribute(on: attributedString)
|
let spacer = try? spacerAttribute.getAttachment() else { return }
|
||||||
tooltipAction.setAttribute(on: attributedString)
|
attributedString.append(NSAttributedString(attachment: spacer))
|
||||||
|
attributedString.append(NSAttributedString(attachment: tooltip))
|
||||||
|
addHandler(on: attributedString)
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(id: UUID = UUID(), action: PassthroughSubject<Void, Never> = PassthroughSubject<Void, Never>(), subscriber: AnyCancellable? = nil, surface: Surface, accessibleText: String? = nil, closeButtonText: String, size: Tooltip.Size, title: String, content: String) {
|
public init(id: UUID = UUID(), action: PassthroughSubject<Void, Never> = PassthroughSubject<Void, Never>(), subscriber: AnyCancellable? = nil, surface: Surface, accessibleText: String? = nil, closeButtonText: String, title: String, content: String) {
|
||||||
self.id = id
|
self.id = id
|
||||||
self.action = action
|
self.action = action
|
||||||
self.subscriber = subscriber
|
self.subscriber = subscriber
|
||||||
self.surface = surface
|
self.surface = surface
|
||||||
self.accessibleText = accessibleText
|
self.accessibleText = accessibleText
|
||||||
self.closeButtonText = closeButtonText
|
self.closeButtonText = closeButtonText
|
||||||
self.size = size
|
|
||||||
self.title = title
|
self.title = title
|
||||||
self.content = content
|
self.content = content
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user