知识点总结 2
2015-06-10 14:13
323 查看
一、按钮的设置
0.设置背景图片
[btn setBackgroundImage:image forState:UIControlStateNormal];
1.设置内部UIImageView的图片
[btn setImage:image forState:UIControlStateNormal];
// 不能写成btn.imageView.image = image;
2.设置内部UILabel的文字
[btn setTitle:@"43" forState:UIControlStateNormal];
// 不能写成btn.titleLabel.text = @"43";
3.调整内部ImageView的frame
- (CGRect)imageRectForContentRect:(CGRect)contentRect
4.调整内部UILabel的frame
- (CGRect)titleRectForContentRect:(CGRect)contentRect
5.覆盖父类在highlighted时的所有操作
- (void)setHighlighted:(BOOL)highlighted { }
6.文字居中
self.titleLabel.textAlignment = NSTextAlignmentCenter;
7.文字大小
self.titleLabel.font = [UIFont systemFontOfSize:12];
8.图片的内容模式
self.imageView.contentMode = UIViewContentModeCenter;
二、添加子控制器
- (void)addChildViewController:
* 会将子控制器添加到childViewControllers,并且子控制器是有顺序的
* 目的就是持有子控制器,不让子控制器销毁,保证主控制器在,子控制器就在
三、让一个控制器拥有导航栏的最快方法:包装一层导航控制器
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller];
四、UIBarButtonItem
1> 创建一个带有文字的item
[[UIBarButtonItem alloc] initWithTitle:@"设置" style:UIBarButtonItemStyleBordered target:nil action:nil]
2> 创建一个包装了自定义View的item
- (id)initWithCustomView:(UIView *)customView
五、设置导航栏UINavigationBar主题
// 1.appearance方法返回一个导航栏的外观对象
// 修改了这个外观对象,相当于修改了整个项目中的外观
UINavigationBar *bar = [UINavigationBar appearance];
// 2.设置导航栏的背景图片
[bar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
// 3.设置导航栏文字的主题
[bar setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColor blackColor],
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]
}];
六、设置导航按钮UIBarButtonItem主题
// 1.修改所有UIBarButtonItem的外观
UIBarButtonItem *barItem = [UIBarButtonItem appearance];
// 2.修改item的背景图片
[barItem setBackgroundImage:image1 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[barItem setBackgroundImage:image2 forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
// 3.修改item上面的文字样式
NSDictionary *dict = @{
UITextAttributeTextColor : [UIColor darkGrayColor],
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]
};
[barItem setTitleTextAttributes:dict forState:UIControlStateNormal];
[barItem setTitleTextAttributes:dict forState:UIControlStateHighlighted];
七、设置状态栏样式
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
0.设置背景图片
[btn setBackgroundImage:image forState:UIControlStateNormal];
1.设置内部UIImageView的图片
[btn setImage:image forState:UIControlStateNormal];
// 不能写成btn.imageView.image = image;
2.设置内部UILabel的文字
[btn setTitle:@"43" forState:UIControlStateNormal];
// 不能写成btn.titleLabel.text = @"43";
3.调整内部ImageView的frame
- (CGRect)imageRectForContentRect:(CGRect)contentRect
4.调整内部UILabel的frame
- (CGRect)titleRectForContentRect:(CGRect)contentRect
5.覆盖父类在highlighted时的所有操作
- (void)setHighlighted:(BOOL)highlighted { }
6.文字居中
self.titleLabel.textAlignment = NSTextAlignmentCenter;
7.文字大小
self.titleLabel.font = [UIFont systemFontOfSize:12];
8.图片的内容模式
self.imageView.contentMode = UIViewContentModeCenter;
二、添加子控制器
- (void)addChildViewController:
* 会将子控制器添加到childViewControllers,并且子控制器是有顺序的
* 目的就是持有子控制器,不让子控制器销毁,保证主控制器在,子控制器就在
三、让一个控制器拥有导航栏的最快方法:包装一层导航控制器
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller];
四、UIBarButtonItem
1> 创建一个带有文字的item
[[UIBarButtonItem alloc] initWithTitle:@"设置" style:UIBarButtonItemStyleBordered target:nil action:nil]
2> 创建一个包装了自定义View的item
- (id)initWithCustomView:(UIView *)customView
五、设置导航栏UINavigationBar主题
// 1.appearance方法返回一个导航栏的外观对象
// 修改了这个外观对象,相当于修改了整个项目中的外观
UINavigationBar *bar = [UINavigationBar appearance];
// 2.设置导航栏的背景图片
[bar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
// 3.设置导航栏文字的主题
[bar setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColor blackColor],
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]
}];
六、设置导航按钮UIBarButtonItem主题
// 1.修改所有UIBarButtonItem的外观
UIBarButtonItem *barItem = [UIBarButtonItem appearance];
// 2.修改item的背景图片
[barItem setBackgroundImage:image1 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[barItem setBackgroundImage:image2 forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
// 3.修改item上面的文字样式
NSDictionary *dict = @{
UITextAttributeTextColor : [UIColor darkGrayColor],
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]
};
[barItem setTitleTextAttributes:dict forState:UIControlStateNormal];
[barItem setTitleTextAttributes:dict forState:UIControlStateHighlighted];
七、设置状态栏样式
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
相关文章推荐
- 链表基本操作
- Note: No relevant classes found. No output generated.
- 互联网架构设计原则
- vSphere Client的拷贝 粘帖 功能
- Linux rsync命令详解
- C++引用
- Android断线监听
- 工厂的进化
- AutoLayout VFL的简单使用
- ASP.NET 生成二维码(采用ThoughtWorks.QRCode和QrCode.Net两种方式)
- 支付宝抢红包图片随机显示jQuery特效
- Linux securecrt破解
- mysql 自已更新更新了日期字段问题
- jQuery插件之ajaxFileUpload
- kindEditor结合jfinal的图文上传功能的实现
- 网上昨天出现的一份纯c语言简历,转过来玩玩,作者很有才
- BlueDroid代码分析之GKI
- Grand Central Dispatch Tutorial for Swift: Part 2/2
- javascript时间格式转换(今天,昨天,前天)
- BUG:ie6\7\8 使用jQuery设置页面标题