小编Xax*_*xus的帖子

嵌入 UIHostingController 中的 NavigationView 具有额外的安全区域插图

有人知道如何处理这个问题吗?似乎当您有一个带有 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 是按如下方式构建的:

  • 有一个全局的 UINavigationViewController
  • UINavigationController 中的第一个也是唯一的项目是这个 UITabBar
  • UITabBar 选项卡都是以编程方式创建的。
  • 有问题的选项卡只是一个 UIHostingController,其中包含您在上面看到的 rootView 代码。

我尝试手动为 UIHostingController …

swift swiftui uihostingcontroller uiviewrepresentable

5
推荐指数
1
解决办法
3502
查看次数

如何在文本 UILabel 周围实现粗描边边框

这就是我想要实现的目标:

在此输入图像描述

这是我尝试过的一些事情:

NS属性字符串

我尝试使用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)

NS属性字符串

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)

在此输入图像描述

core-graphics uikit nsattributedstring uilabel swift

5
推荐指数
1
解决办法
1273
查看次数