How do I set the size of a SF Symbol in SwiftUI?
Asked Answered
T

5

138

How do I set the size of a SF Symbol in Xcode 11 using SwiftUI?

Teresitateressa answered 3/8, 2019 at 21:19 Comment(0)
T
220

SF Symbols are similar to fonts, thus:

.font(.system(size: 60))
Teresitateressa answered 3/8, 2019 at 21:20 Comment(4)
Interesting. Very counter-intuitive since SF Symbols are used inside ImageSlack
Not really, especially when you think about web dev and font awesomesYesseniayester
@Slack I agree with. Not just counter intuitive but weirdCardoso
The top answer should include the tip from @mathias-bak about being able to use .imageScale(Image.Scale).Symbolize
V
107

An alternative is to use .imageScale().

Image(systemName: "chevron.left").imageScale(.small)
Image(systemName: "chevron.left").imageScale(.medium)
Image(systemName: "chevron.left").imageScale(.large)
Vansickle answered 4/6, 2020 at 15:9 Comment(1)
These seems to be the recommended way to apply scaling. See developer.apple.com/videos/play/wwdc2020/10207Tryma
C
82

You can set weights and sizes:

Image(systemName: "checkmark.circle")
    .font(.system(size: 16, weight: .ultraLight))
Image(systemName: "checkmark.circle")
    .font(.system(size: 16, weight: .thin))
Image(systemName: "checkmark.circle")
    .font(.system(size: 16, weight: .light))
Image(systemName: "checkmark.circle")
    .font(.system(size: 16, weight: .regular))
Image(systemName: "checkmark.circle")
    .font(.system(size: 16, weight: .medium))
Image(systemName: "checkmark.circle")
    .font(.system(size: 16, weight: .semibold))
Image(systemName: "checkmark.circle")
    .font(.system(size: 16, weight: .bold))
Image(systemName: "checkmark.circle")
    .font(.system(size: 16, weight: .heavy))
Image(systemName: "checkmark.circle")
    .font(.system(size: 16, weight: .black))
Certainly answered 15/11, 2019 at 4:0 Comment(0)
Y
35

If you want to use frame you can as well:

Image(systemName: "plus")
     .resizable()
     .scaledToFit()
     .frame(width: 24, height: 24)
Yablon answered 23/2, 2022 at 13:46 Comment(1)
This actually sets the exact size, unlike font approach. Good.Garlicky
M
5

Since iconographic SF Symbols are deeply integrated into the San Francisco system font (at the moment, we have 4000+ of them), they can be edited using vector graphics tools and can be manipulated habitual way.

var body: some View {
    
    Image(systemName: "swift").imageScale(.large)
    
    HStack {
        // Spacer()            
        Label("Swift", systemImage: "swift").scaleEffect(2)       
        // Spacer()
        Text("Swift \(Image(systemName: "swift"))").font(.largeTitle) 
        // Spacer()
    }
}

enter image description here

Mme answered 2/8, 2022 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.