为什么 .medium 系统字体未在 SwiftUI 中显示为 .title 样式?
我还尝试使用 Font.custom 显式设置字体...
Text("Text").font(Font.title.weight(.light))
Text("Text").font(Font.title.weight(.regular))
Text("Text").font(Font.title.weight(.medium))
Text("Text").font(Font.title.weight(.semibold))
Text("Text").font(Font.title.weight(.bold))
Run Code Online (Sandbox Code Playgroud)
这是我的输出:
我期待 .medium 比 .regular 重。

我正在尝试创建 ViewModifiers 来保存我在 SwiftUI 中的所有类型样式。当我尝试添加 .fontWeight 修饰符时,出现以下错误:
Value of type 'some View' has no member 'fontWeight'
这可能吗?有没有更好的方法来管理我的 SwiftUI 项目中的类型样式?
struct H1: ViewModifier {
func body(content: Content) -> some View {
content
.foregroundColor(Color.black)
.font(.system(size: 24))
.fontWeight(.semibold)
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 UIViewRepresentable 结构在 SwiftUI 中嵌入一个“使用 Apple 登录”按钮来显示按钮。
import SwiftUI
import UIKit
import AuthenticationServices
final class AppleIDButton: UIViewRepresentable {
typealias UIViewType = UIView
var appleButton = ASAuthorizationAppleIDButton()
func makeUIView(context: UIViewRepresentableContext<AppleIDButton>) -> UIView {
let view = UIView()
view.addSubview(appleButton)
return view
}
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<AppleIDButton>) {
appleButton.cornerRadius = 8
}
}
Run Code Online (Sandbox Code Playgroud)
...//这是我的 SwiftUI 文件中的代码
ZStack(alignment: .top) {
VStack(spacing: 0) {
Rectangle()
.frame(width: screenWidth, height: 1)
.foregroundColor(Color("lineGray"))
Rectangle()
.frame(width: screenWidth, height: screenHeight * 0.375)
.foregroundColor(.white)
}
VStack {
HStack { …Run Code Online (Sandbox Code Playgroud) 尝试将SwiftUI颜色更改为UIColor的实例。
我可以轻松地从UIColor中获取RGBA,但是我不知道如何获取“ Color”实例以返回相应的RGB和不透明度值。
@EnvironmentObject var colorStore: ColorStore
init() {
let red = //get red value from colorStore.primaryThemeColor
let green = //get red value from colorStore.primaryThemeColor
let blue = //get red value from colorStore.primaryThemeColor
let opacity = //get red value from colorStore.primaryThemeColor
let color = UIColor(red: red, green: green, blue: blue, alpha: opacity)
UINavigationBar.appearance().tintColor = color
}
Run Code Online (Sandbox Code Playgroud)
...或者也许有更好的方法来完成我想要的。