iOS13段控件自定义

iOS13段控件自定义,ios,swift,uisegmentedcontrol,Ios,Swift,Uisegmentedcontrol,刚刚升级到iOS 13和Xcode 11,我可以看到我们应用程序中的段控件已经被替换,我们漂亮的颜色和风格现在被忽略了 我想把它们恢复到以前的状态,我在AppDelegate中使用了下面的代码。didFinishLaunchingWithOptions UISegmentedControl.appearance().setTitleTextAttributes(segmentAttributes , for: .normal) UISegmentedControl.appearance().se

刚刚升级到iOS 13和Xcode 11,我可以看到我们应用程序中的段控件已经被替换,我们漂亮的颜色和风格现在被忽略了

我想把它们恢复到以前的状态,我在
AppDelegate中使用了下面的代码。didFinishLaunchingWithOptions

UISegmentedControl.appearance().setTitleTextAttributes(segmentAttributes , for: .normal)
UISegmentedControl.appearance().setTitleTextAttributes(segmentSelectedAttributes , for: .selected)
UISegmentedControl.appearance().setBackgroundImage(UIImage.imageWithColor(UIColor.white, size: CGSize(width: 1, height: 1)), for: .normal, barMetrics: .default)
UISegmentedControl.appearance().setBackgroundImage(UIImage.imageWithColor(uicolor_normal, size: CGSize(width: 1, height: 1)), for: .selected, barMetrics: .default)
UISegmentedControl.appearance().setDividerImage(UIImage.imageWithColor(uicolor_normal, size: CGSize(width: 1, height: 1)),forLeftSegmentState: .normal, rightSegmentState: .normal, barMetrics: .default)
谢谢你的指点。然而,有些东西还没有被恢复,我相信这与
层有关,比如:

layer.borderWidth = 1
layer.borderColor = UIColor.blue
layer.masksToBounds = true
layer.cornerRadius = 2
(边框宽度、边框颜色和角半径) 现在,上面链接的问题显示添加了这些内容,但我想将此代码放在一个地方(AppDelegate.didfishlaunchingwithoptions),以保持代码的整洁。因此,我尝试添加以下内容:

UISegmentedControl.appearance().layer.borderWidth = 1
UISegmentedControl.appearance().layer.borderColor = uicolor_normal.cgColor
UISegmentedControl.appearance().layer.masksToBounds = true
UISegmentedControl.appearance().layer.cornerRadius = 2
不幸的是,这似乎不起作用。也许是因为它需要等到画出来?我确实遇到过一些提供类似于使用UINavigationBar的东西,但这也不起作用:

extension UINavigationBar {

  var castShadow : String {
    get { return "anything fake" }
    set {
        self.layer.shadowOffset = CGSizeMake(0, 3)
        self.layer.shadowRadius = 3.0
        self.layer.shadowColor = UIColor.yellowColor().CGColor
        self.layer.shadowOpacity = 0.7

    }
  }

}
// below should go in didFinishLaunchingWithOptions...
UINavigationBar.appearance().castShadow = ""
有人能提供一些建议,说明如何影响所有分段控件的图层,而不在我的ViewController中添加/更改任何代码吗

非常感谢