Created
May 17, 2017 09:46
-
-
Save OctoberHammer/61f7e5799cd78dc1ba1443c7ee48f706 to your computer and use it in GitHub Desktop.
GradientInBackgroundOfNavigationBarAndStatusBar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainController: UINavigationController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.navigationBar.isTranslucent = false | |
self.navigationBar.tintColor = UIColor.blue | |
let fontDictionary = [ NSForegroundColorAttributeName:UIColor.red ] | |
self.navigationBar.titleTextAttributes = fontDictionary | |
self.navigationBar.setBackgroundImage(imageLayerForGradientBackground(), for: UIBarMetrics.default) | |
/*if self.revealViewController() != nil { | |
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer()) | |
}*/ | |
} | |
private func imageLayerForGradientBackground() -> UIImage { | |
var updatedFrame = self.navigationBar.bounds | |
// take into account the status bar | |
updatedFrame.size.height += 20//Возможно дело в этом | |
//0xfebf00 - более темный | |
let upperColor = UIColor(red: 0xFE/255.0, green: 0xBF/255.0, blue: 0x00/255.0, alpha: 1.0); | |
//0xfcda03 - более СВЕТЛЫЙ | |
let lowerColor = UIColor(red: 0xFC/255.0, green: 0xDA/255.0, blue: 0x03/255.0, alpha: 1.0); | |
//let layer = CAGradientLayer() | |
let layer = CAGradientLayer.gradientLayerForBounds(bounds: updatedFrame, upperColor: upperColor, lowerColor: lowerColor) | |
// CAGradientLayer.gradientLayerForBounds(bounds: updatedFrame, startColor: UIColor(), endColor: UIColor()) | |
layer.bounds = updatedFrame | |
UIGraphicsBeginImageContext(layer.bounds.size) | |
layer.render(in: UIGraphicsGetCurrentContext()!) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return image! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment