iOS 5自定义UI
2013-10-09 12:51
204 查看
代码摘自: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
#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
相关文章推荐
- 猫猫学IOS(十七)UI之纯代码自定义Cell实现新浪微博UI
- IOS UI view button 自定义颜色………
- 猫猫学IOS(十七)UI之纯代码自定义Cell实现新浪微博UI
- iOS-UI控件之UITableView(二)- 自定义不等高的cell
- iOS开发UI高级—31CAlayer(自定义layer)
- iOS-UI基础(自定义TableViewCell)
- iOS自定义相机界面,实现微信小视频UI效果
- ios iphone 自定义UIPickerView
- iOS开发之有趣的UI —— 自定义不等高cell
- (素材源码)猫猫学IOS(十七)UI之纯代码自定义Cell实现新浪微博UI
- iOS学习笔记43——iOS6下自定义UI控件外观效果
- (素材源码)猫猫学IOS(十七)UI之纯代码自定义Cell实现新浪微博UI
- iOS 简单易用的二维码扫描及生成二维码三方控件LFQRCode,可灵活自定义UI
- Android UI之自定义——类似iOS的Tabbar
- iOS之UI TabBarcontroller----自定义tabBar/改变tabBar中间按钮的样式(一)
- IOS开发UI:自定义TabB 4000 ar
- IOS-9-UIBarButtonItem导航条-添加自定义Left或者Right按钮
- IOS之UI--自定义按钮实现代理监听点击事件
- iOS开发——UI基础-自定义构造方法,layoutSubviews,Xib文件,利用Xib自定义View