How do i set a weight to SF Symbols for iOS 13?

2020-03-08 08:54发布

I have this

Image(systemName: "arrow.right")

But how do i make it bold, semibold etc?

I am using the new SwiftUI.

4条回答
Explosion°爆炸
2楼-- · 2020-03-08 09:34

When using the font modifier, set a weight to the font you're passing

Image(systemName: "arrow.right")
  .font(Font.title.weight(.ultraLight))
查看更多
▲ chillily
3楼-- · 2020-03-08 09:34

For UIKit, symbols can be configured as follows:

UIImage(systemName: "arrow.right",
        withConfiguration: UIImage.SymbolConfiguration(pointSize: 16, weight: .bold))
查看更多
干净又极端
4楼-- · 2020-03-08 09:50

UIKit SWIFT 5.x

To set their attributes: create a configuration then pass it in as a parameter:

let imageConfig = UIImage.SymbolConfiguration(pointSize: 22, weight: .black, scale: .large)
let image = UIImage(systemName: "delete.right", withConfiguration: imageConfig)
查看更多
聊天终结者
5楼-- · 2020-03-08 09:55

SwiftUI 1.0

I just wanted to also mention how to change the weight along with a custom font size.

HStack(spacing: 40) {
    Image(systemName: "moon.zzz")
        .font(Font.system(size: 60, weight: .ultraLight))
    Image(systemName: "moon.zzz")
        .font(Font.system(size: 60, weight: .light))
    Image(systemName: "moon.zzz")
        .font(Font.system(size: 60, weight: .regular))
    Image(systemName: "moon.zzz")
        .font(Font.system(size: 60, weight: .bold))
}

Example of Font Size and weight

查看更多
登录 后发表回答