Skip to content

kean/Formatting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Formatting

An example code for kean.blog: Formatted Localizable Strings. Demonstrates how to implement basic string formatting using XML tags.

let input = "M1 delivers up to <b>2.8x faster</b> processing performance than the <a href='%@'>previous generation.</a>"
let text = String(format: input, "https://support.apple.com/kb/SP799")
let style = FormattedStringStyle(attributes: [
    "body": [.font: UIFont.systemFont(ofSize: 15)],
    "b": [.font: UIFont.boldSystemFont(ofSize: 15)],
    "a": [.underlineColor: UIColor.clear]
])
label.attributedText = NSAttributedString(formatting: text, style: style)

Result using standard UILabel:

Screen Shot 2020-11-29 at 18 07 03

Minimum Requirements

Versio Swift Xcode Platforms
Formatting 4.0 Swift 5.8 Xcode 14.3 iOS 12.0, tvOS 12.0, watchOS 5.0, macOS 10.5

License

Formatting is available under the MIT license. See the LICENSE file for more info.