我正在尝试使用新的iOS导航栏外观API配置我的应用程序的后退按钮指示器,但是它不起作用:
let bar = self.navigationController!.navigationBar
let sz = CGSize(20,20)
let arrow = UIImage(systemName:"arrowtriangle.left")!
let indic =
UIGraphicsImageRenderer(size:sz).image { ctx in
arrow.draw(in:CGRect(0,0,20,20)) // indicator is arrow
}
let indicmask =
UIGraphicsImageRenderer(size:sz).image { ctx in
ctx.fill(CGRect(0,0,20,20)) // mask is entire image
}
bar.standardAppearance.setBackIndicatorImage(
indic, transitionMaskImage: indicmask)
我所看到的只是一个大的蓝色矩形。
这是怎么回事?
答案 0 :(得分:2)
这是一个非常愚蠢的错误:Apple的参数向后!只需将图像交换到应放置蒙版的位置,然后将蒙版移至应放置图像的位置,一切都会很好:
let bar = self.navigationController!.navigationBar
let sz = CGSize(20,20)
let arrow = UIImage(systemName:"arrowtriangle.left")!
let indic =
UIGraphicsImageRenderer(size:sz).image { ctx in
arrow.draw(in:CGRect(0,0,20,20)) // indicator is arrow
}
let indicmask =
UIGraphicsImageRenderer(size:sz).image { ctx in
ctx.fill(CGRect(0,0,20,20)) // mask is entire image
}
bar.standardAppearance.setBackIndicatorImage(
indicmask, transitionMaskImage: indic) // swap!