// 1.设置导航栏背景
UINavigationBar *bar = [UINavigationBar appearance];
[bar setBackgroundImage:[UIImage resizeImage:@"NavigationBar_Background.png"] forBarMetrics:UIBarMetricsDefault];
// 状态栏
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
// 2.设置导航栏文字属性
NSMutableDictionary *barAttrs = [NSMutableDictionary dictionary];
[barAttrs setObject:[UIColor darkGrayColor] forKey:UITextAttributeTextColor];
[barAttrs setObject:[NSValue valueWithUIOffset:UIOffsetMake(0, 0)] forKey:UITextAttributeTextShadowOffset];
[bar setTitleTextAttributes:barAttrs];
// 3.按钮
UIBarButtonItem *item = [UIBarButtonItem appearance];
[item setBackgroundImage:[UIImage resizeImage:@"BarButtonItem_Normal.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[item setBackgroundImage:[UIImage resizeImage:@"BarButtonItem_Pressed.png"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
NSMutableDictionary *itemAttrs = [NSMutableDictionary dictionaryWithDictionary:barAttrs];
[itemAttrs setObject:[UIFont boldSystemFontOfSize:13] forKey:UITextAttributeFont];
[item setTitleTextAttributes:itemAttrs forState:UIControlStateNormal];
[item setTitleTextAttributes:itemAttrs forState:UIControlStateHighlighted];
[item setTitleTextAttributes:itemAttrs forState:UIControlStateDisabled];
// 4.返回按钮
[item setBackButtonBackgroundImage:[UIImage resizeImage:@"BarButtonItem_Back_Normal.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[item setBackButtonBackgroundImage:[UIImage resizeImage:@"BarButtonItem_Back_Pressed.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
搞了半天,居然没有发现可以插入Objective-C代码的地方。真郁闷
//
// UIImage+Fit.m
// SinaWeibo
//
// Created by mj on 13-8-19.
// Copyright (c) 2013年 itcast. All rights reserved.
//
#import "UIImage+Fit.h"
@implementation UIImage (Fit)
#pragma mark 返回拉伸好的图片
+ (UIImage *)resizeImage:(NSString *)imgName {
return [[UIImage imageNamed:imgName] resizeImage];
}
- (UIImage *)resizeImage
{
CGFloat leftCap = self.size.width * 0.5f;
CGFloat topCap = self.size.height * 0.5f;
return [self stretchableImageWithLeftCapWidth:leftCap topCapHeight:topCap];
}
- (UIImage *)cut:(CGSize)sizeScale
{
CGFloat width = self.size.width * sizeScale.width;
CGFloat height = self.size.height * sizeScale.height;
CGFloat x = (self.size.width - width) * 0.5;
CGFloat y = (self.size.height - height) * 0.5;
CGRect rect = CGRectMake(x, y, width, height);
CGImageRef ref = CGImageCreateWithImageInRect(self.CGImage, rect);
return [UIImage imageWithCGImage:ref];
}
@end