iOS 5自定义UI

代码摘自:http://www.raywenderlich.com/49316/how-to-update-your-app-for-ios-7


#if CUSTOM_APPEARANCE


UIColor *DarkTextColor;

UIColor *LightTextColor;

UIColor *SeparatorColor;

UIColor *TableColor;


- (void)customizeAppearance

{

// Colors

DarkTextColor = [UIColor colorWithRed:59/255.0f green:29/255.0f blue:19/255.0f alpha:1.0f];

LightTextColor = [UIColor colorWithRed:195/255.0f green:143/255.0f blue:89/255.0f alpha:1.0f];

SeparatorColor = [UIColor colorWithRed:209/255.0f green:184/255.0f blue:157/255.0f alpha:1.0f];

TableColor = [UIColor colorWithRed:240/255.0f green:227/255.0f blue:213/255.0f alpha:1.0f];


// Navigation Bar

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavBarBackground-Portrait"] forBarMetrics:UIBarMetricsDefault];

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavBarBackground-Landscape"] forBarMetrics:UIBarMetricsLandscapePhone];


[[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"ShadowDown"]];

[[UINavigationBar appearance] setTitleTextAttributes:@{

UITextAttributeTextColor : [UIColor whiteColor],

UITextAttributeTextShadowColor : [UIColor blackColor],

UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(0.0f, -1.0f)],

}];


// Buttons for Navigation Bar


UIImage *barButtonPortrait = [[UIImage imageNamed:@"BarButtonItem-Portrait"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0f, 7.0f, 0.0f, 7.0f)];

UIImage *barButtonLandscape = [[UIImage imageNamed:@"BarButtonItem-Landscape"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0f, 7.0f, 0.0f, 7.0f)];


[[UIBarButtonItem appearance] setBackgroundImage:barButtonPortrait forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

[[UIBarButtonItem appearance] setBackgroundImage:barButtonLandscape forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];

 

[[UIBarButtonItem appearance] setTitleTextAttributes:@{

UITextAttributeTextColor : [UIColor whiteColor],

UITextAttributeTextShadowColor : [UIColor blackColor],

UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(0.0f, -1.0f)],

}

forState:UIControlStateNormal];


UIImage *backButtonPortrait = [[UIImage imageNamed:@"BackButton-Portrait"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0f, 18.0f, 0.0f, 7.0f)];

UIImage *backButtonLandscape = [[UIImage imageNamed:@"BackButton-Landscape"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0f, 18.0f, 0.0f, 7.0f)];


[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonPortrait forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonLandscape forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];


// Tab Bar


[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"TabBarBackground"]];

[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"ShadowUp"]];

[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"TabBarSelection"]];


[[UITabBarItem appearance] setTitleTextAttributes:@{

UITextAttributeTextColor : [UIColor colorWithRed:206/255.0f green:161/255.0f blue:109/255.0f alpha:1.0f],

UITextAttributeTextShadowColor : [UIColor colorWithWhite:0.0f alpha:0.5f],

UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],

}

forState:UIControlStateNormal];


[[UITabBarItem appearance] setTitleTextAttributes:@{

UITextAttributeTextColor : [UIColor colorWithRed:219/255.0f green:202/255.0f blue:184/255.0f alpha:1.0f],

UITextAttributeTextShadowColor : [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.5f],

UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(0.0f, -1.0f)],

}

forState:UIControlStateSelected];

// Toolbar

[[UIToolbar appearance] setBackgroundImage:[UIImage imageNamed:@"ToolbarBackground"] forToolbarPosition:UIToolbarPositionBottom barMetrics:UIBarMetricsDefault];

[[UIToolbar appearance] setShadowImage:[UIImage imageNamed:@"ShadowUp"] forToolbarPosition:UIToolbarPositionBottom];

// Search Bar


[[UISearchBar appearance] setBackgroundImage:[UIImage imageNamed:@"SearchBarBackground"]];

// Segmented Control

UIImage *segmentImage = [[UIImage imageNamed:@"SegmentedControl"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0f, 15.0f, 0.0f, 15.0f)];


[[UISegmentedControl appearance] setBackgroundImage:segmentImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];


[[UISegmentedControl appearance] setDividerImage:[UIImage imageNamed:@"SegmentedControlDivider"]

forLeftSegmentState:UIControlStateNormal

rightSegmentState:UIControlStateNormal

barMetrics:UIBarMetricsDefault];

}


#endif




评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值