IOS5自定义用户界面(主要内容记录)
来源:互联网 发布:淘宝steam慈善包 编辑:程序博客网 时间:2024/06/05 17:36
原文地址:http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5
一、添加背景图片
- (void)viewDidLoad { [super viewDidLoad]; [[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_sand"]]]; }
二、自定义UINavigationBar
IOS5提供了2个新的API帮助我们解决这个问题:
1. UINavigationBar有一个新的backgroundImage属性。
2. UIImage有一个新的resizableImageWithCapInsets方法,我们可以用它创建一个可调整大小的图像。
- (void)customizeAppearance{ // Create resizable images UIImage *gradientImage44 = [[UIImage imageNamed:@"surf_gradient_textured_44"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; UIImage *gradientImage32 = [[UIImage imageNamed:@"surf_gradient_textured_32"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; // Set the background image for *all* UINavigationBars [[UINavigationBar appearance] setBackgroundImage:gradientImage44 forBarMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setBackgroundImage:gradientImage32 forBarMetrics:UIBarMetricsLandscapePhone]; // Customize the title text for *all* UINavigationBars [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0], UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"Arial-Bold" size:0.0], UITextAttributeFont, nil]]; }前2行使用resizableImageWithCapInsets创建可拉伸的图像,stretchableImageWithLeftCapWidth:topCapHeight:方法已经被废弃。
在application:didFinishLaunchingWithOptions:方法中调用[self customizeAppearance]即可。
三、自定义UIBarButtonItem
UIImage *button30 = [[UIImage imageNamed:@"button_textured_30"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];UIImage *button24 = [[UIImage imageNamed:@"button_textured_24"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];[[UIBarButtonItem appearance] setBackgroundImage:button30 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];[[UIBarButtonItem appearance] setBackgroundImage:button24 forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone]; [[UIBarButtonItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0], UITextAttributeTextColor, [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"AmericanTypewriter" size:0.0], UITextAttributeFont, nil] forState:UIControlStateNormal];
四、自定义UITabBar
UIImage *tabBackground = [[UIImage imageNamed:@"tab_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];[[UITabBar appearance] setBackgroundImage:tabBackground];[[UITabBar appearance] setSelectionIndicatorImage: [UIImage imageNamed:@"tab_select_indicator"]];
五、自定义UISlider
在IOS5中自定义UISlider很简单,只需设置UISlider的“maximumTrackImage”,“minimumTrackImage”,“thumbImage”属性。
UIImage *minImage = [[UIImage imageNamed:@"slider_minimum.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];UIImage *maxImage = [[UIImage imageNamed:@"slider_maximum.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];UIImage *thumbImage = [UIImage imageNamed:@"thumb.png"]; [[UISlider appearance] setMaximumTrackImage:maxImage forState:UIControlStateNormal];[[UISlider appearance] setMinimumTrackImage:minImage forState:UIControlStateNormal];[[UISlider appearance] setThumbImage:thumbImage forState:UIControlStateNormal];
六、自定义UISegmentedControl
UIImage *segmentSelected = [[UIImage imageNamed:@"segcontrol_sel.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];UIImage *segmentUnselected = [[UIImage imageNamed:@"segcontrol_uns.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];UIImage *segmentSelectedUnselected = [UIImage imageNamed:@"segcontrol_sel-uns.png"];UIImage *segUnselectedSelected = [UIImage imageNamed:@"segcontrol_uns-sel.png"];UIImage *segmentUnselectedUnselected = [UIImage imageNamed:@"segcontrol_uns-uns.png"]; [[UISegmentedControl appearance] setBackgroundImage:segmentUnselected forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];[[UISegmentedControl appearance] setBackgroundImage:segmentSelected forState:UIControlStateSelected barMetrics:UIBarMetricsDefault]; [[UISegmentedControl appearance] setDividerImage:segmentUnselectedUnselected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];[[UISegmentedControl appearance] setDividerImage:segmentSelectedUnselected forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];[[UISegmentedControl appearance] setDividerImage:segUnselectedSelected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
七、自定义UISwitch
假设我们已经有了一个IBOutlet - rentSwitch,在viewDidLoad方法中添加以下代码:
[rentSwitch setOnTintColor:[UIColor colorWithRed:0 green:175.0/255.0 blue:176.0/255.0 alpha:1.0]];
八、自定义UILabel
- Font: Custom
- Family: American Typewriter
- Style: Regular
- Size: 16
使用UITextField delegates的drawRect方法设置textfield的背景
- (void)drawRect:(CGRect)rect{ UIImage *textFieldBackground = [[UIImage imageNamed:@"text_field_teal.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15.0, 5.0, 15.0, 5.0)]; [textFieldBackground drawInRect:[self bounds]];}
- IOS5自定义用户界面(主要内容记录)
- Ios5 基础二 –丰富的用户界面
- 如何在iOS5中定制用户界面
- 如何在iOS5中定制用户界面
- ios5自定义导航条
- ios5 自定义导航条问题
- ios5 自定义导航条问题
- ios5 自定义导航条问题
- 主要内容
- 创建自定义排序用户界面
- customUIStyle自定义用户界面
- [ios开发ios5新特性之]如何在iOS5中定制用户界面
- Xcode5 支持 iOS5 问题解决过程记录
- ios5 自定义导航条问题 UINavigationBar
- ios5 自定义导航条问题 UINavigationBar
- ios5 自定义导航条的问题
- ios5 自定义导航条问题 UINavigationBar
- [翻译]用户界面和产品自定义
- string和wstring相互转换
- 伤感的QQ空间日志_爱情的动漫是你我的最爱
- 运算符的优先级
- fflush()的理解
- 找出重复的整数
- IOS5自定义用户界面(主要内容记录)
- 贪心算法精讲
- axis2常用命令(wsdl2java)
- Java读取xml文件的四种方法
- QNX多线程同步之Barrier(屏障)
- MYSQL常用查命令
- Linux下pthread的读写锁的优先级问题
- poj 3009 TLE
- 资源网站