iOS development changes the height and background picture of Uinavigationcontroller Uinavigationbar

Source: Internet
Author: User

1, change the height

New categories for customizing Uinavigationbar:

[CPP] View plaincopy
    1. Uinavigationbar+backgoundimage.h
    2. #import <Foundation/Foundation.h>
    3. @interface Uinavigationbar (Backgoundimage)
    4. @end


In the implementation of the new category, methods that overwrite the original class-(void) DrawRect: (cgrect) Rect:

[CPP] View plaincopy
  1. Uinavigationbar+backgoundimage.m
  2. #import "Uinavigationbar+backgoundimage.h"
  3. @implementation Uinavigationbar (Backgoundimage)
  4. -(void) Layoutsubviews {
  5. CGRect barframe = self.frame;
  6. BarFrame.size.height = 100.0; //New heights
  7. Self.frame = Barframe;
  8. }
  9. In fact, only need to overwrite the method on the line, the self.frame.size.height changed to 100.0 OK
  10. -(void) DrawRect: (cgrect) rect {
  11. UIImage *image = [UIImage imagenamed:@"Logo.png"];
  12. [Image drawinrect:cgrectmake (0, 0, Self.frame.size.width, self.frame.size.height)];
  13. }
  14. @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
    1. -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
    2. {
    3. //......      
    4. return YES;
    5. }

"Return YES" before adding the code:

[CPP] View plaincopy
    1. [[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.