eg. Like we have a NSAttributed string and we need to separate string and attributes, then use these attributes on other string of same length.
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
You should take a look at this method from NSAttributedString
By calling this method at NSAttributedString you will receive all attributes applied in range. Just specify all string as range. And then create new attributes string with these attributes.
An NSAttributedString may have different attributes for different ranges of the string.
To extract these attributes, you can use the
enumerateAttributesInRange
method.We prepare an array of tuples to hold the results:
Each tuple will hold the attributes for a specific range in the NSAttributedString.
Now we iterate on the NSAttributedString and populate the array with the results:
Once the array is populated, you can access the contents:
And from there you have all you need to create new attributed strings with these attributes: you have the range and the corresponding attributes for each one in the NSAttributedString.