- 论坛徽章:
- 0
|
UINavigationBar设置背景图片
头文件:
Ios代码- 1.#import <Foundation/Foundation.h>
- 2.
- 3.@interface UINavigationBar (BackgroundImage)
- 4.
- 5.UIImageView *backgroundView;
- 6.- (void)setBackgroundImage:(UIImage *)image;
- 7.
- 8.@end
复制代码 实现文件:
Ios代码- 1.#import "UINavigationBar.h"
- 2.
- 3.@implementation UINavigationBar (BackgroundImage)
- 4.
- 5.- (void)setBackgroundImage:(UIImage*)image
- 6.{
- 7. if(image == nil)
- 8. {
- 9. [backgroundView removeFromSuperview];
- 10. }
- 11. else
- 12. {
- 13. backgroundView = [[UIImageView alloc] initWithImage:image];
- 14. backgroundView.frame = CGRectMake(0.f, 0.f, self.frame.size.width, self.frame.size.height);
- 15. backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- 16. [self addSubview:backgroundView];
- 17. [self sendSubviewToBack:backgroundView];
- 18. [backgroundView release];
- 19. }
- 20.}
- 21.
- 22.@end
复制代码 |
|