I'm trying to use the new iOS navigation bar appearance API to configure my app's back button indicator, but it isn't working:
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)
All I'm seeing is a big blue rectangle.
What's going on?
It's a very silly bug: Apple has the parameters backward, Just swap the image to go where the mask should be and the mask to go where the image should be: and all will be well:
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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.