有人知道如何处理这个问题吗?似乎当您有一个带有 NavigationView 的 UIHostingController 时,会发生以下情况:
注意大的灰色标签栏安全区域。
这主要是一个 UIKit 应用程序。我们正在用 swiftUI 视图替换选项卡栏中的一些选项卡。
这是我的代码:
var body: some View {
NavigationView {
ZStack {
MapKitMapView(
mapView: mapView,
annotations: $annotations,
polylines: $polylines,
centerCoordinate: $centerCoordinate,
newMapRegion: $newMapRegion,
userTrackingMode: $userTrackingMode
)
.edgesIgnoringSafeArea(.all)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
ButtonLayer(mapView: mapView, userTrackingMode: $userTrackingMode, showSheet: $showSheet)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(.margin)
}
.edgesIgnoringSafeArea(.all)
.navigationBarHidden(true)
.sheet(isPresented: $showSheet) {
SettingsView()
}
}
}
Run Code Online (Sandbox Code Playgroud)
请原谅审查制度。我希望该应用程序保持匿名。
但本质上我的 UITabBar 是按如下方式构建的:
我尝试手动为 UIHostingController …
这就是我想要实现的目标:
这是我尝试过的一些事情:
我尝试使用NSAttributedString以下属性,但 iOS 14+ 中的文本路径似乎存在错误
private var attributes: [NSAttributedString.Key: Any] {
[
.strokeColor : strokeColor,
.strokeWidth : -8,
.foregroundColor : foregroundColor,
.font: UIFont.systemFont(ofSize: 17, weight: .black)
]
}
Run Code Online (Sandbox Code Playgroud)
NSAttributedString如果某些字母没有出现奇怪的路径问题,我对这个结果非常满意。
我也尝试过覆盖drawText,但据我所知,我找不到任何方法来改变笔划粗细并将其与下一个字符混合在一起:
override func drawText(in rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
context?.setLineJoin(.round)
context?.setTextDrawingMode(.stroke)
self.textColor = strokeColor
super.drawText(in: rect)
context?.setTextDrawingMode(.fill)
self.textColor = foregroundColor
super.drawText(in: rect)
layer.shadowColor = UIColor.black.cgColor
layer.shadowRadius = 2
layer.shadowOpacity = 0.08
layer.shadowOffset = .init(width: 0, height: 2)
}
Run Code Online (Sandbox Code Playgroud)