Say I have a Button in SwiftUI:
Button("Tap me") {
print("Button tapped!")
}
How can I can I make the font size of the Button's text larger and bold?
Say I have a Button in SwiftUI:
Button("Tap me") {
print("Button tapped!")
}
How can I can I make the font size of the Button's text larger and bold?
Use the bold() Text modifier on a Button's label.
Example:
Button {
print("Button tapped!")
} label: {
Text("Tap me").bold()
}
To make the text larger and bold, just chain the modifiers:
Button {
print("Button tapped!")
} label: {
Text("Tap me")
.font(.title)
.bold()
}
You are right about using .system(size: )
on macOS you need to create a PlainButtonStyle button in order for the text to stay inside the button. This is how I have done it
Button("Tap me") {
print("Button Tapped!")
}.padding()
.font(.system(size: 20, weight: Font.Weight.bold))
.foregroundColor(Color.white)
.background(RoundedRectangle(cornerRadius: 8).fill(Color.blue))
.buttonStyle(PlainButtonStyle())
Button("Tap me") {
print("Button tapped!")
}.font(.system(size: 30, weight: .bold, design: .default))
If you are using a toolbar and want the confirmation/add/save button to be bold, as it's standard in iOS, you just have tell the the toolbar that your button is a confirmation item.
List {
// ...
}
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Button("Add") {
// ...
}
}
}
You simply wrap your button in a ToolbarItem with the placement: .confirmationAction.
That way, the button will be placed on the top right in your toolbar and appears bold as well.
You can increase font size with .font(.system(size: <font size>)) method. As for the bold part, you can put text between two pairs of *. This allows you to make bold specific parts of text or the whole thing.
Button(action: {},
label: {
Text("Tap **me**").font(.system(size: <font size>))
})