SmartString - A powerful and small library that will allow the creation of complex String Styles

Related tags

Guides SmartString
Overview

SmartString

A powerful and small library that will allow the creation of complex String Styles. Provides also an easy way to handle TAPPING on each substring!

Example

  • Basic
let smartString = "Hello world!"
    .font(.boldSystemFont(ofSize: 30))
    .color(.blue)
    .underline()
    .shadow(SmartShadow()

label.smartString = smartString

// Using Closures

let smartString = "Hello world!"
    .font { .boldSystemFont(ofSize: 30) }
    .color { .blue }
    .shadow { .default }
    .underline()

label.smartString = smartString

Result

Predefined Style

let style = SmartStringStyle(
    color: .blue,
    font: .boldSystemFont(ofSize: 30),
    shadow: SmartShadow(
    offset: CGSize(width: 2, height: 2),
    radius: 2,
    color: .red
)

label.smartString = "Hello world!".style(style)

Result

String + SmartString interpolation

let smartString = "Hello"
    .font(.boldSystemFont(ofSize: 30))
    .color(.green)
    .underline()
    .italic()
    .shadow(.default)
+ " world!"
    .font(.systemFont(ofSize: 24))
    .color(.purple)
    
label.smartString = smartString

Result

String + SmartString interpolation using predefined Styles

let style1 = SmartStringStyle(
    color: .green,
     font: .boldSystemFont(ofSize: 30),
   shadow: .default
)
        
let style2 = SmartStringStyle(
    color: .purple,
     font: .systemFont(ofSize: 24)
)
        
let smartString = "Hello"
    .style(style1)
+ " world!"
    .style(style2)
    
label.smartString = smartString

Result

Label substring Tap Handlers

let smartString = "Hello "
    .font { .systemFont(ofSize: 18) }
    .onTap { string in
        print(string) // This will print "Hello " when tapping the substring "Hello " within the label
    }
+ "world"
    .color(.red)
    .bold()
    .onTap { string in
        print(string) // This will print "world" when tapping the substring "world" within the label
    }
+ "!"
    
label.smartString = smartString

Result

You might also like...
Swift library of lightweight interfaces for prototyping, bridged to JS

Prototope Prototope is a lightweight, high-performance prototyping framework. Its goals are: making simple things very easy making complex things poss

CoreDragon is a drag'n'drop library for iOS applications
CoreDragon is a drag'n'drop library for iOS applications

CoreDragon is a drag'n'drop library for iOS applications. Instead of using context menus, modal view controllers, share sheets and other "indirect manipulation" ways of moving data around, it's much more intuitive to just grab the thing you want to move, and drop it on the place where you want to move it to.

Swift Client library to interact with Supabase Functions.

functions-swift Swift Client library to interact with Supabase Functions. Usage let client = FunctionsClient( url: URL(string: "https://project-id.s

iOS native app demo with Xcode and Swift using MVVM architecture and Apple's Combine framework for functional reactive programming, all with UIKit
iOS native app demo with Xcode and Swift using MVVM architecture and Apple's Combine framework for functional reactive programming, all with UIKit

iOS (Swift 5): MVVM test with Combine and UIKit MVVM and functional reactive programming (FRP) are very used in iOS development inside companies. Here

Explanations and samples about the Swift programming language
Explanations and samples about the Swift programming language

About Swift Contents Explanations and samples about: Swift Programming Language Swift Standard Library Target audience Developers familiar with object

👨‍💻Watch the latest and greatest conference videos on your Mac
👨‍💻Watch the latest and greatest conference videos on your Mac

Conferences.digital is the best way to watch the latest and greatest videos from your favourite developer conferences for free on your Mac. Either sea

SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.
SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

A package to help track how often the user opened the app and if they opened it in the current version before.

AppOpenTracker AppOpenTracker provides an observable AppOpenTracker.shared instance that can be used to track the last version that the app was opened

Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets.
Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets.

SwiftUI-LazyVGrid Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets. Screenshots Samples IP & Credits All those b

Comments
  • Extend tap area?

    Extend tap area?

    Is it possible to expand the tap area for text? A single line of text in a label not so easy to tap on. There is very little vertical area on the tap.

    opened by tkirby 4
  • How to get attributed text back from SmartString?

    How to get attributed text back from SmartString?

    Super cool library btw. Really takes the hassle out of constructing attributed strings and adding actions.

    I'd like to use a SmartString to format a UIButton but can't figure out how to get the attributed test into .setAttirbutedTitle(...)

    opened by tkirby 1
Owner
Valerio
Valerio
This is an iOS Safari Extension Sample that adds a "Develop menu" to Safari on iOS to allow you to analyze websites.

Develop Menu for Mobile Safari This is an iOS Safari Extension that adds a "Develop menu" to Safari on iOS to allow you to analyze websites. This is a

Watanabe Toshinori 1 Dec 7, 2022
A Swift package that adds some handy functions to String and NSMutableAttributedString

StringBooster StringBooster is a simple Swift package containing a few useful ex

B.T. Franklin 0 Dec 31, 2022
The Optimus Prime of string inflection

The Optimus Prime of string inflection let swiftString = "created_at".swiftCase() let rubyString = "createdAt".rubyCase() Contribute Fork it Create y

Christoffer Winterkvist 22 Apr 25, 2018
A small app that uses the private FlightUtilities.framework to show information about any flight.

FlightUtilities A small app that uses the private FlightUtilities.framework to show information about any flight given the airline code, flight code a

Patrick Balestra 31 Dec 20, 2022
Rabble Wabble - This is small Project implemented with respected design patterns

Rabble_Wabble This is small Project implemented with respected design patterns D

Ahmed Amin 2 Feb 2, 2022
⚛️ A Reactive Data-Binding and Dependency Injection Library for SwiftUI x Concurrency.

SwiftUI Atom Properties A Reactive Data-Binding and Dependency Injection Library for SwiftUI x Concurrency ?? API Reference Introduction Examples Gett

Ryo Aoyama 199 Dec 17, 2022
DCL Private Library

DCLPrivateLibrary Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation

null 0 Nov 28, 2021
SwiftUI module library for adding seasons theme animations to your app

HolidayThemes SwiftUI module library for adding seasons theme animations to your app. Requirements iOS 13.0+ Xcode 12.0+ Installation Swift Package Ma

null 2 Mar 7, 2022
This library is a UIView that is capable of Picture-in-Picture (PiP) in iOS.

>> 日本語 UIPiPView This library is a UIView that is capable of Picture-in-Picture (PiP) in iOS. Using this library, information that is updated in real

Akihiro Urushihara 128 Jan 4, 2023