1、创建自己的样式文件
//MyStyleSheet.h
#import <Three20/Three20.h>
#import <Three20Style/TTDefaultStyleSheet.h>
#import <Three20Style/TTDefaultStyleSheet+DragRefreshHeader.h>
@interface MyStyleSheet : TTDefaultStyleSheet
@end
//MyStyleSheet.m
#import "MyStyleSheet.h"
#import <Three20UI/UIViewAdditions.h>
@implementation MyStyleSheet
- (UIFont*)font {
return [UIFont fontWithName:@"Arial" size:14];
}
- (UIFont*)tableFont {
return [UIFont fontWithName:@"Arial" size:14];
}
- (UIFont*)tableHeaderPlainFont {
return [UIFont fontWithName:@"Arial" size:14];
}
- (UIFont*)tableButtonFont{
return [UIFont fontWithName:@"Arial" size:14];
}
- (UIFont*)tableTitleFont{
return [UIFont fontWithName:@"Arial" size:17];
}
- (UIFont*)titleFont {
return [UIFont fontWithName:@"Arial" size:17];
}
- (UIColor*)tableGroupedBackgroundColor {
//return RGBCOLOR(224, 221, 203);
return mainBgByImg;
}
- (UIColor*)tableHeaderTextColor {
//return [UIColor brownColor];
return [UIColor blackColor];
}
- (UIColor*)tableHeaderTintColor {
return RGBCOLOR(224, 221, 203);
}
- (UIColor*)navigationBarTintColor {
//return RGBCOLOR(100, 128, 108);
return RGBCOLOR(0, 119, 188);
}
- (UIColor*)toolbarTintColor{
return RGBCOLOR(0, 119, 188);
}
- (TTStyle*)largeText {
return [TTTextStyle styleWithFont:[UIFont boldSystemFontOfSize:18] next:nil];
}
- (TTStyle*)blueBox {
return
[TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithRadius:0] next:
[TTInsetStyle styleWithInset:UIEdgeInsetsMake(0, -5, -4, -6) next:
[TTShadowStyle styleWithColor:[UIColor grayColor] blur:2 offset:CGSizeMake(1,1) next:
[TTSolidFillStyle styleWithColor:[UIColor cyanColor] next:
[TTSolidBorderStyle styleWithColor:[UIColor grayColor] width:1 next:nil]]]]];
}
- (TTStyle*)viewInnerShadow {
return
[TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithRadius:0] next:
[TTShadowStyle styleWithColor:RGBACOLOR(0,0,0,0.5) blur:8 offset:CGSizeMake(2, 2) next:
[TTInsetStyle styleWithInset:UIEdgeInsetsMake(0.25, 0.25, 0.25, 0.25) next:
[TTSolidFillStyle styleWithColor:[UIColor whiteColor] next:
[TTInsetStyle styleWithInset:UIEdgeInsetsMake(-0.25, -0.25, -0.25, -0.25) next:
[TTInnerShadowStyle styleWithColor:RGBACOLOR(0,0,0,0.5) blur:6 offset:CGSizeMake(1, 1) next:nil]]]]]];
}
- (TTStyle*)launcherButton:(UIControlState)state {
return
[TTPartStyle styleWithName:@"image"
style:TTSTYLESTATE(launcherButtonImage:, state)
next:[TTTextStyle styleWithFont:[UIFont boldSystemFontOfSize:14]
color:[UIColor blackColor]
minimumFontSize:14
shadowColor:nil
shadowOffset:CGSizeZero
next:nil]];
}
- (TTStyle*)blackForwardButton:(UIControlState)state {
TTShape* shape = [TTRoundedRightArrowShape shapeWithRadius:4.5];
UIColor* tintColor = RGBCOLOR(0, 119, 188);
return [TTSTYLESHEET toolbarButtonForState:state shape:shape tintColor:tintColor font:nil];
}
- (TTStyle*)blueToolbarButton:(UIControlState)state {
TTShape* shape = [TTRoundedRectangleShape shapeWithRadius:4.5];
UIColor* tintColor = RGBCOLOR(30, 110, 255);
return [TTSTYLESHEET toolbarButtonForState:state shape:shape tintColor:tintColor font:nil];
}
@end
2、调用样式
1) #import "StyleSheet.h"
2) 初始化调用的样式类
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[TTStyleSheet setGlobalStyleSheet:[[[MyStyleSheet alloc] init] autorelease]]; //在这里初始化
}
return self;
}
3) 使用样式
TTButton : TTButton *backBtn = [TTButton buttonWithStyle:@"toolbarBackButton:" title:@"返回"];
TTView *topView = [[TTView alloc] initWithFrame:CGRectMake(0, 0, appFrame.size.width, 80)];
topView.style = [[TTStyleSheet globalStyleSheet] styleWithSelector:@"viewInnerShadow"]; //指定样式名称;
topView.backgroundColor = self.view.backgroundColor;
[self.view addSubview:topView];