Apply various colors depending on character classifications
- TextColorizer is a Swift package designed to enhance text readability and aesthetic appeal by applying different colors to various types of characters within a string.
- This package is ideal for applications that require clear visual categorization of text, such as educational tools, code editors, or any user interface that benefits from enhanced text features.
- Dynamic Text Coloring: Automatically assigns colors to letters, numbers, and symbols within a text.
- Customizable Color Schemes: Supports custom color schemes for different character types.
- SwiftUI Support: Easily integrates with SwiftUI for iOS and macOS applications.
To use the TextColorizer
package in your Swift project, you can follow these steps to apply color schemes to different types of characters within a string:
-
Import the
TextColorizer
package in your Swift file:import TextColorizer
-
Define a string that you want to colorize:
let sampleText = "Hello123!"
-
Use the
attributedString
function to apply colors to the string:let coloredText = AttributedString.attributedString(text: sampleText)
-
Display the colored text in your SwiftUI view (if using SwiftUI):
Text(coloredText)
Here is a complete example of a SwiftUI view that uses TextColorizer
:
import SwiftUI
import TextColorizer
struct ContentView: View {
var body: some View {
let sampleText = "Hello123!"
let coloredText = AttributedString.attributedString(text: sampleText, colors: (.orange, .pink, .indigo))
return Text(coloredText)
}
}
To integrate the TextColorizer
package into your Swift project using Swift Package Manager, you can follow these steps:
- Open your Xcode project.
- Navigate to
File
->Swift Packages
->Add Package Dependency...
. - Paste the repository URL:
https://github.com/sentryco/TextColorizer.git
- Choose the branch
main
to always use the latest version on the main branch. - Click on
Next
and select the target where you want to use the library.
Ensure that your Package.swift
includes TextColorizer
as a dependency:
// swift-tools-version:5.9
import PackageDescription
let package = Package(
name: "YourPackageName",
products: [
.library(
name: "YourPackageName",
targets: ["YourTargetName"]),
],
dependencies: [
.package(url: "https://github.com/sentryco/TextColorizer", branch: "main")
],
targets: [
.target(
name: "YourTargetName",
dependencies: ["TextColorizer"]),
.testTarget(
name: "YourPackageNameTests",
dependencies: ["YourTargetName"]),
]
)
- HybridColor Support: TextColorizer utilizes the
HybridColor
package to support dynamic color schemes, including automatic adjustments for dark and light modes on macOS and iOS. This ensures that TextColorizer can seamlessly adapt to user interface style changes.
- Fix the issue with light and dark colors from macOS
- Remove tests?