1, change the height
New categories for customizing Uinavigationbar:
[CPP] View plaincopy
- Uinavigationbar+backgoundimage.h
- #import <Foundation/Foundation.h>
- @interface Uinavigationbar (Backgoundimage)
- @end
In the implementation of the new category, methods that overwrite the original class-(void) DrawRect: (cgrect) Rect:
[CPP] View plaincopy
- Uinavigationbar+backgoundimage.m
- #import "Uinavigationbar+backgoundimage.h"
- @implementation Uinavigationbar (Backgoundimage)
- -(void) Layoutsubviews {
- CGRect barframe = self.frame;
- BarFrame.size.height = 100.0; //New heights
- Self.frame = Barframe;
- }
- In fact, only need to overwrite the method on the line, the self.frame.size.height changed to 100.0 OK
- -(void) DrawRect: (cgrect) rect {
- UIImage *image = [UIImage imagenamed:@"Logo.png"];
- [Image drawinrect:cgrectmake (0, 0, Self.frame.size.width, self.frame.size.height)];
- }
- @end
The height of the Navigationbar in the project can be found to have changed.
2, next change the background image, (refer to http://stackoverflow.com/questions/8375092/ Xcode4-2-storyboard-navigation-controller-how-to-set-custom-image-for-uinavig):
The delegate method in XXXAPPDALEGATE.M:
[CPP] View plaincopy
- -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
- {
- //......
- return YES;
- }
"Return YES" before adding the code:
[CPP] View plaincopy
- [[Uinavigationbar appearance] setbackgroundimage:[uiimage imagenamed:@"Logo.png"] forbarmetrics: Uibarmetricsdefault]; //this adds the image
Success.
The height of the 1th step can be directly taken to the height of the picture, so it is more convenient.
iOS development changes the height and background picture of Uinavigationcontroller Uinavigationbar