To respect the original author of the article, reprint must indicate the original address: http://www.cnblogs.com/wt616/p/3784717.html
Look first:
When customizing the navigation bar background, you may experience some of the following issues:
1. When the navigation bar background is set, the color of the status bar will change along with it, which may not be what you said you wanted to see.
2, IOS7 more than the version and the lower version of the navigation bar displayed the height of the difference, this difference is the status bar height 20, in order to be compatible with the lower version, must be unified
Solution Ideas:
1, abnormal is the status bar background also changed, and the status bar text can be set through other APIs: such as [[uiapplicationsharedapplication] Setstatusbarstyle:uistatusbarstylelightcontent];
2, the text is attached to the background above, so consider inserting a rectangular color between this block (even the picture can)
3, according to this idea, the second way of thinking is also produced, is to produce a 20+44=64 height of the picture, as the navigation bar background, where the top 20 is the color of the status bar.
4, this article realizes the first kind of thought, and the simulator and the real machine as well as the ios6,7 have verified the feasible
More than 7.0 versions solve high-rise problems with a single line of code
if ([[[[uidevicecurrentdevice] systemversion] doublevalue ]>=7.0) {
self. Edgesforextendedlayout=uirectedgenone;
}
Create a false status bar background with a height of 20
UIView *statusbarview = [[UIView alloc] initwithframe:cgrectmake(0,- )] ;
Set it to the color you need, here I choose black, I am very calm
Statusbarview. backgroundcolor=[uicolor blackcolor];
Here my idea is: before the ideal state is the status bar color has become the color of the navigation bar, but according to this situation, but instead help me to determine that the status bar at this time is also part of the navigation bar, and the status bar text floating above, So, in theory, adding a subview directly to the navigation bar is the middle layer of them.
Push the code like this:
[self. Navigationcontroller. Navigationbar addsubview: Statusbarview];
Modify the navigation bar text color, here I choose White, that I am very pure
[[uiapplicationsharedapplication] setstatusbarstyle: Uistatusbarstylelightcontent];
Set the background picture of the navigation bar
[self. Navigationcontroller . navigationbarsetbackgroundimage: [UIImageimagenamed:@ "bg.jpg" ] forbarmetrics:uibarmetricsdefault];