mirror of
https://github.com/luxfi/safe-ios.git
synced 2026-10-30 15:19:20 +00:00
* gh-3144 Add url for social login info article * gh-3144 Add social login info modal sheet * gh-3144 Process partial label clicks; navigate to social login info screen * gh-3144 Adjust label * gh-3144 Add shield icon for info box * gh-3144 Add disclaimer info box
47 lines
1.8 KiB
Swift
47 lines
1.8 KiB
Swift
//
|
|
// UIGestures.swift
|
|
// Multisig
|
|
//
|
|
// Created by Vitaly on 13.07.23.
|
|
// Copyright © 2023 Gnosis Ltd. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
extension UITapGestureRecognizer {
|
|
|
|
func didTapAttributedTextInLabel(label: UILabel, inRange targetRange: NSRange) -> Bool {
|
|
// Create instances of NSLayoutManager, NSTextContainer and NSTextStorage
|
|
let layoutManager = NSLayoutManager()
|
|
let textContainer = NSTextContainer(size: CGSize.zero)
|
|
let textStorage = NSTextStorage(attributedString: label.attributedText!)
|
|
|
|
// Configure layoutManager and textStorage
|
|
layoutManager.addTextContainer(textContainer)
|
|
textStorage.addLayoutManager(layoutManager)
|
|
|
|
// Configure textContainer
|
|
textContainer.lineFragmentPadding = 0.0
|
|
textContainer.lineBreakMode = label.lineBreakMode
|
|
textContainer.maximumNumberOfLines = label.numberOfLines
|
|
let labelSize = label.bounds.size
|
|
textContainer.size = labelSize
|
|
|
|
// Find the tapped character location and compare it to the specified range
|
|
let locationOfTouchInLabel = self.location(in: label)
|
|
let textBoundingBox = layoutManager.usedRect(for: textContainer)
|
|
let textContainerOffset = CGPoint(
|
|
x: (labelSize.width - textBoundingBox.size.width) * 0.5 - textBoundingBox.origin.x,
|
|
y: (labelSize.height - textBoundingBox.size.height) * 0.5 - textBoundingBox.origin.y
|
|
)
|
|
let locationOfTouchInTextContainer = CGPoint(
|
|
x: locationOfTouchInLabel.x - textContainerOffset.x,
|
|
y: locationOfTouchInLabel.y - textContainerOffset.y
|
|
)
|
|
let indexOfCharacter = layoutManager.characterIndex(for: locationOfTouchInTextContainer, in: textContainer, fractionOfDistanceBetweenInsertionPoints: nil)
|
|
|
|
return NSLocationInRange(indexOfCharacter, targetRange)
|
|
}
|
|
|
|
}
|