I want to convert the program to a tintcolor
in the UIIN navigationbar and place the gradient in the interface Wish Builder
When I change tintcolor
in my code, the gradient disappears, but when I change the tintcolor
in the interface builder, the gradient Is kept.
Any ideas?
So this is an old question, but I stumbled when I was searching for some such question Which seems like this question but is different Hopefully it will help someone else (or that someone else will show me a better way) ...
You have a custom on UID navigation How do the shields apply?
- (CALayer *) gradientBGLayerForBounds: ( CGRect) Limitations {CAGradientLayer * gradientBG = [CAGradientLayer layer]; GradientBG.frame = Border; GradientBG.colors = @ [[ID] [[UIColor redColor] CGColor], (ID) [[UIColor purpleColor] CGColor]]; Return Gradient BG; }
We go there, a shield that looks like a suspected makeup of a punk rocker, which is good, because this code is for the fictional app I Have A Punk -Rocker with suspicious taste in my pocket that name should be a bit longer ..
Now I want this layer on my UI, which should be easy? Just add it as a novel, right? The problem here is that it will cover amazing buttons and accessories that UIDAVentron gives you. This is bad.
Instead, we look at the amazing feature method in IOS5 + to change the format of all the UIBarbar (s) in our app:
[[UINavigationBar presence] SetBackgroundImage: SOME_IMAGEBarMetrics for: UIBarMetricsDefault];
There is only one problem here that we do not have a UIImage, we have a CALayer to do what is a punk-spirited enthusiast?
Claire * bgGradientLayer = [Self Gradient Bizzleer Forbes: ONE_OF_YOUR_NAV_CONTROLLERS.navigationBar.bounds]; UIGraphicsBeginImageContext (bgGradientLayer.bounds.size); [BGGrand Layer RenderIncontext: UigrexGetCertChat Contex ()]; UIImage * bgAsImage = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext ();
So now we have changed our CALayer to a UIImage (hopefully), so whatever remains it is to set it:
If (bgAsImage! =) Zero) {[UINavigationBar presence] setBackgroundImage: bgAsImage forBarMetrics: UIBarMetricsDefault]; } Else {NSLog (@ "Shield BG Failed to Make Image, User will see standard tint color gradient.");
What I like about this solution
- The centralized code for all UIBarbar (S) in my app (in appelete)
- Tintoll will still be honored for all the univisioned buttons (back, editing, etc.)
- If UIImage fails in creation, then my UINA navigation bar (s) will still respect tint
- I do not have to rely on real image processing / easy to update
But I am still not convinced that this is the best way. So, enjoy if it helps you, tell me how you can improve it if you can.
~ Thanks
Comments
Post a Comment