Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari-style back button

I've not found on stackoverflow a modern solution how to make a Safari-style back button for UIBarButtonItem. Is there a simple and elegant way to implement a back button as it is in Safari?

Safari toolbar screenshot

like image 401
ucelme Avatar asked Feb 18 '26 07:02

ucelme


2 Answers

If you are targeting iOS13 and above, you can use the built-in SF Symbols library provided by Apple.

The chevron.left image is used for the Safari back button.

let chevronLeft = UIImage(systemName: "chevron.left")
let backButton = UIBarButtonItem(image: chevronLeft, style: .plain, target: webView, action: #selector(webView!.goBack))

These icons also come in nine weights from ultralight to black, which can be applied like this.

let chevronLeft = UIImage(systemName: "chevron.left", withConfiguration: UIImage.SymbolConfiguration(weight: .thin))

More information is available from Apple here: SF Symbols

like image 185
Chris Avatar answered Feb 19 '26 19:02

Chris


I have found solution. The best way is to find back button image on web and use this code:

    let backIcon = UIImage(named: "backIcon")
    let backButton = UIBarButtonItem(image: backIcon, style: .plain, target: webView, action: #selector(webView!.goBack))

For example:

enter image description here enter image description here enter image description here

like image 22
ucelme Avatar answered Feb 19 '26 20:02

ucelme



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!