A macro designed to help make static text more accessible by generating dynamically scaling text instead.
Go to File > Add Package Dependencies and paste in https://github.com/Mcrich23/AccessibleText.git and add the AccessibleText
framework to your target.
Add the following to the dependencies
section of your Package.swift
:
dependencies: [
.package(url: "https://github.com/Mcrich23/AccessibleText.git", from: "1.0.0")
]
Then add AccessibleText
to your target dependencies:
targets: [
.target(
name: "YourTarget",
dependencies: [
.product(name: "AccessibleText", package: "AccessibleText")
]
)
]
Before you can use this macro, you have to set it up with the project.
AccessibleText uses LM Studio. It will use qwen3:4b
unless otherwise specified with the environment variable LM_STUDIO_MODEL
.
Note: The model will automatically download if it is not already present on your machine.
- Go to your target's
Build Phases
tab and create a newRun Script
phase. - Drag the phase to be above your
Compile Sources
phase - Uncheck
Based on dependency analysis
- Paste in the following code
base_url="$(echo "$BUILT_PRODUCTS_DIR" | sed -E 's|(.*DerivedData/[^/]+).*|\1|')"
bash "$base_url/SourcePackages/checkouts/AccessibleText/Scripts/text-gen.sh" "$SRCROOT/<Target Folder>"
- Replace
<Target Folder>
with the folder that contains the code for the target.
Note: You can also override the default prompt by setting the
PROMPT_INSTRUCTIONS
environment variable.
The run phase references the shell script from this package's source files and then creates a file in your project. To do this, you must disable User Scripting Sandbox
.
- Go to your target's
Build Settings
tab - Filter for
User Scripting Sandbox
- Set
User Scripting Sandbox
toNo
accessibleText
is a dynamic text scaler for SwiftUI. To use accessibleText
, reference it in a View
body with a static string.
Note: While the string should be mostly static, you can use variables in it.
When you build your project, the compile script you added when setting up the macro will create/update AccessibleTextContainer.swift
with text options for the string in your macro call.
Note: This will not be modified unless you change the string in the macro. You can change the text options that were generated without any concern.
struct ContentView: View {
let name: String = "Morris"
let feature = "accessibility"
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
#accessibleText("Hi \(name)! I am testing \(feature)")
}
.padding()
}
}
accessibleNavigationTitle
dynamically scales the navigationTitle
for its contents. To use accessibleNavigationTitle
, reference it in a View
body with a static string.
Note: While the string should be mostly static, you can use variables in it.
When you build your project, the compile script you added when setting up the macro will create/update AccessibleTextContainer.swift
with text options for the string in your macro call.
Note: This will not be modified unless you change the string in the macro. You can change the text options that were generated without any concern.
struct ContentView: View {
let name: String = "Morris"
let feature = "accessibility"
var body: some View {
#accessibleNavigationTitle("Hi \(name)! I am testing \(feature)", content: {
ScrollView {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
#accessibleText("Hi \(name)! I am testing \(feature)")
}
.padding()
}
})
}
}