Skip to content

Instantly share code, notes, and snippets.

@dan085
Forked from hcn1519/backbutton.swift
Created February 23, 2020 16:58
Show Gist options
  • Save dan085/615eba216fc808877231ec837ab1229a to your computer and use it in GitHub Desktop.
Save dan085/615eba216fc808877231ec837ab1229a to your computer and use it in GitHub Desktop.
/ back 버튼 여백 적용 메소드
extension UIImage {
func imageWithInsets(insets: UIEdgeInsets) -> UIImage {
UIGraphicsBeginImageContextWithOptions(
CGSize(width: self.size.width + insets.left + insets.right,
height: self.size.height + insets.top + insets.bottom),
false, self.scale)
guard UIGraphicsGetCurrentContext() != nil else { return UIImage() }
let origin = CGPoint(x: insets.left, y: insets.top)
self.draw(at: origin)
guard let imageWithInsets = UIGraphicsGetImageFromCurrentImageContext() else { return UIImage() }
UIGraphicsEndImageContext()
return imageWithInsets
}
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// back Button
let backImage = #imageLiteral(resourceName: "left_white").imageWithInsets(insets: UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 0))
let navbarAppearace = UINavigationBar.appearance()
navbarAppearace.backIndicatorTransitionMaskImage = backImage
navbarAppearace.backIndicatorImage = backImage
navbarAppearace.barStyle = .black
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment