beginning work on hero.

This commit is contained in:
Kevin G Christiano 2019-09-16 10:24:18 -04:00
parent 52679e95f3
commit 6f4db10d33
2 changed files with 46 additions and 0 deletions

View File

@ -502,6 +502,47 @@ public typealias ActionBlock = () -> ()
let accessibleAction = customAccessibilityAction(range: range)
clauses.append(ActionableClause(range: range, actionBlock: actionBlock, accessibilityID: accessibleAction?.hash ?? -1))
}
// func rectOfCharacter() {
//
//// label.intrinsicContentSize.width
// if let range = mylabel.text?.range(of: String(describing: mylabel.text?.characters.last!)) {
// let prefix = mylabel.text?.substring(to: range.lowerBound)
// let size: CGSize = prefix!.size(attributes: [NSFontAttributeName: UIFont.systemFont(ofSize: 35.0)])
// let position = CGPoint(x:size.width,y: 0)
// myScrollView.setContentOffset(position, animated: true)
// }
// }
static func boundingRect(forCharacterRange range: NSRange, in label: Label) -> CGRect {
guard let attributedText = label.attributedText else { return CGRect() }
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = label.textAlignment
let stagedAttributedString = NSMutableAttributedString(attributedString: attributedText)
stagedAttributedString.addAttributes([NSAttributedString.Key.paragraphStyle: paragraph], range: NSRange(location: 0, length: attributedText.string.count))
let textStorage = NSTextStorage(attributedString: stagedAttributedString)
let layoutManager = NSLayoutManager()
let textContainer = NSTextContainer(size: .zero)
layoutManager.addTextContainer(textContainer)
textStorage.addLayoutManager(layoutManager)
textContainer.lineFragmentPadding = 0
textContainer.lineBreakMode = label.lineBreakMode
textContainer.maximumNumberOfLines = label.numberOfLines
textContainer.size = label.bounds.size
var glyphRange = NSRange()
// Convert the range for glyphs.
layoutManager.characterRange(forGlyphRange: range, actualGlyphRange: &glyphRange)
return layoutManager.boundingRect(forGlyphRange: glyphRange, in: textContainer)
}
}
// MARK: - Atomization

View File

@ -166,5 +166,10 @@ import UIKit
} else {
button.isHidden = true
}
if let text = header.messageLabel.text, text.contains("frog") {
let rect = Label.boundingRect(forCharacterRange: NSRange(location: 65, length: 4), in: header.messageLabel)
print(rect)
}
}
}