Comments (2)
@annehiro This is actually fairly easy. Since a gradient color is simply a UIColor,
you can use Apple's UIAppearance protocol to do exactly what you want.
Here's a quick example to get you started. In your app's delegate, simply do the following:
//1. Define the frame for our GradientColor to cover (default navigation bar size)
CGRect defaultNavigationBarFrame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64);
//2. Create an array of colors you'd like to use in your gradient
NSArray *colors = [NSArray arrayWithObjects:FlatYellow, FlatRed, nil];
//3. Create your gradient color
UIColor *myGradientColor = [UIColor colorWithGradientStyle:UIGradientStyleTopToBottom
withFrame:defaultNavigationBarFrame
andColors:colors];
//4. Modify the barTintColor for all instances of UINavigationBar
[[UINavigationBar appearance] setBarTintColor:myGradientColor];
Of course, you could also simplify it down to one line of code:
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithGradientStyle:UIGradientStyleTopToBottom
withFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64)
andColors:[NSArray arrayWithObjects:FlatYellow, FlatRed, nil]]];
And if that's not short enough, you can use Chameleon Shorthand to shorten it even more.
[[UINavigationBar appearance] setBarTintColor:GradientColor(UIGradientStyleTopToBottom,
CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64),
(@[FlatYellow, FlatRed]))];
Note: Don't forget to add a set of parentheses around your color array if using Chameleon Shorthand.
Hopefully this is enough to get you started. Let me know if you have anymore questions. 😃
from chameleon.
I'm gonna go ahead and close this, since it seems like you may have figured it out. Feel free to open up a new issue if you're having any other troubles. 👍
from chameleon.
Related Issues (20)
- Tableview scrolling is clunky when I am applying the gradient colors to the views in my tableview cell.
- Navigation Bar Hairline won't hide with a searchController in Navigation Bar
- CIEDE2000 algorithm incorrect HOT 2
- Semantic Issue - Enumeration value 'kGCColorSpaceModelXYZ' not handled in switch : UIColor+ Chameleon.m
- NSInvalidArgumentException HOT 4
- Editor placeholder in source file HOT 4
- No support for latest version of swift. HOT 6
- No gradient with tableView editActionsForRowAt
- hidesNavigationBarHairline does not work on iPhone x/xr/xs/max
- Swift 5 supporting folk? HOT 8
- Getting Complementary colors (Analogous etc.) don't return the proper colors. HOT 1
- Function produces expected type 'UIColor'; did you mean to call it with '()'? HOT 13
- Xcode 11.1 issue HOT 10
- [Question] - Color Depth / Pixel Depth
- Am getting an error while using update carthage command
- Library not loaded
- Enumeration value 'kCGColorSpaceModelXYZ' not handled in switch
- Gradient starts giving rare hex values
- Building not working on Xcode 12
- Build fails with message "Function produces expected type 'UIColor()'; did you mean to call it with '()'?" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chameleon.