UI初级之界面特别处理技巧二
2015-09-06 13:41
357 查看
内容提要:UI界面的特别处理技巧二
一、问题说明:修改标签管理器标签和视图控制器标题不一样
使用标签管理器来管理导航控制器,
//self.title = @"home”;//当前视图的title(上面标题)
//self.navigationItem.title = @"home";
//上述方法无效,要找准层级关系
//标签管理器的子控制器是导航管理器
//当前视图所对应的TabBarItem的标题(下面的标题)
self.navigationController.tabBarItem.title = @"home1";
二、视图控器继承实现风格相似
在使用导航控制器的时候,导航控制器管理许多个子视图控制器,如果这些子控制器的页面风格是相似的,我们可以设置一个父类,使这些子控制器都继承与这个父类,如设置一个BaseViewController类,在其viewDidLoad实现如下的操作
//如下的操作使每一个子视图的背景图片都一致
- (void)viewDidLoad
{
//子类也会这样调用,这样可以使一部分样式与父类相同
[super viewDidLoad];
UIImage *img
= [UIImage imageNamed:@"bj.jpg"];
UIGraphicsBeginImageContext(CGSizeMake(kScreenWidth, kScreenHeight));
[img drawInRect:[UIScreen mainScreen].bounds];
img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor =
[UIColor colorWithPatternImage:img];
}
三、设置项目全局的导航栏样式
//注意:所有带UI_APPEARANCE_SELECTOR宏修饰的方法都可以全局设置
//创建导航控制器
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:rootVC];
//处理图片
UIImage *img
= [UIImage imageNamed:@"navbar_bg_normal.png"];
UIGraphicsBeginImageContext(CGSizeMake(kScreenWidth,
64));
[img drawInRect:CGRectMake(0,
0, kScreenWidth, 64)];
img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//1.设置项目全局的导航栏的背景图片
[[UINavigationBar appearance] setBackgroundImage:imgforBarMetrics:UIBarMetricsDefault];
//2.设置项目全局的导航栏的字体样式,
//也可以单独的设置字体的大小或者颜色,这样的话,没有设置的一项就会采用默认显示,所以最好还是同时设置
[[UINavigationBar appearance]setTitleTextAttributes:@{NSFontAttributeName:
[UIFontboldSystemFontOfSize:16], NSForegroundColorAttributeName:
[UIColorwhiteColor]}];
四、自定义UI组件
//这里是一个示例,自定义一个Button
#import <UIKit/UIKit.h>
@interface WXButton : UIControl
{
UIImageView *_checkImg;
}
@property (nonatomic, strong) UIImageView *checkImg;
- (id)initWithFrame:(CGRect)frame
ImageName:(NSString *)imgName;
@end
//实现
#import "WXButton.h"
@implementation WXButton
- (id)initWithFrame:(CGRect)frame
ImageName:(NSString *)imgName
{
self = [super initWithFrame:frame];
if (self)
{
//...
//添加UI,设置跟随的图片获取其他相关属性
_checkImg =
[[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width -
18, frame.size.height -
18, 18, 18)];
_checkImg.image =
[UIImage imageNamed:@"checkmark.png"];
_checkImg.hidden = YES;
[self addSubview:_checkImg];
//设置自己的背景图片
[self setBackgroundColor:[UIColor colorWithPatternImage:[UIImageimageNamed:imgName]]];
// [self addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
//设置默认的点击事件
//- (void)btnClick
//{
// checkImg.hidden = !checkImg.hidden;
//}
@end
一、问题说明:修改标签管理器标签和视图控制器标题不一样
使用标签管理器来管理导航控制器,
//self.title = @"home”;//当前视图的title(上面标题)
//self.navigationItem.title = @"home";
//上述方法无效,要找准层级关系
//标签管理器的子控制器是导航管理器
//当前视图所对应的TabBarItem的标题(下面的标题)
self.navigationController.tabBarItem.title = @"home1";
二、视图控器继承实现风格相似
在使用导航控制器的时候,导航控制器管理许多个子视图控制器,如果这些子控制器的页面风格是相似的,我们可以设置一个父类,使这些子控制器都继承与这个父类,如设置一个BaseViewController类,在其viewDidLoad实现如下的操作
//如下的操作使每一个子视图的背景图片都一致
- (void)viewDidLoad
{
//子类也会这样调用,这样可以使一部分样式与父类相同
[super viewDidLoad];
UIImage *img
= [UIImage imageNamed:@"bj.jpg"];
UIGraphicsBeginImageContext(CGSizeMake(kScreenWidth, kScreenHeight));
[img drawInRect:[UIScreen mainScreen].bounds];
img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor =
[UIColor colorWithPatternImage:img];
}
三、设置项目全局的导航栏样式
//注意:所有带UI_APPEARANCE_SELECTOR宏修饰的方法都可以全局设置
//创建导航控制器
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:rootVC];
//处理图片
UIImage *img
= [UIImage imageNamed:@"navbar_bg_normal.png"];
UIGraphicsBeginImageContext(CGSizeMake(kScreenWidth,
64));
[img drawInRect:CGRectMake(0,
0, kScreenWidth, 64)];
img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//1.设置项目全局的导航栏的背景图片
[[UINavigationBar appearance] setBackgroundImage:imgforBarMetrics:UIBarMetricsDefault];
//2.设置项目全局的导航栏的字体样式,
//也可以单独的设置字体的大小或者颜色,这样的话,没有设置的一项就会采用默认显示,所以最好还是同时设置
[[UINavigationBar appearance]setTitleTextAttributes:@{NSFontAttributeName:
[UIFontboldSystemFontOfSize:16], NSForegroundColorAttributeName:
[UIColorwhiteColor]}];
四、自定义UI组件
//这里是一个示例,自定义一个Button
#import <UIKit/UIKit.h>
@interface WXButton : UIControl
{
UIImageView *_checkImg;
}
@property (nonatomic, strong) UIImageView *checkImg;
- (id)initWithFrame:(CGRect)frame
ImageName:(NSString *)imgName;
@end
//实现
#import "WXButton.h"
@implementation WXButton
- (id)initWithFrame:(CGRect)frame
ImageName:(NSString *)imgName
{
self = [super initWithFrame:frame];
if (self)
{
//...
//添加UI,设置跟随的图片获取其他相关属性
_checkImg =
[[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width -
18, frame.size.height -
18, 18, 18)];
_checkImg.image =
[UIImage imageNamed:@"checkmark.png"];
_checkImg.hidden = YES;
[self addSubview:_checkImg];
//设置自己的背景图片
[self setBackgroundColor:[UIColor colorWithPatternImage:[UIImageimageNamed:imgName]]];
// [self addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
//设置默认的点击事件
//- (void)btnClick
//{
// checkImg.hidden = !checkImg.hidden;
//}
@end
相关文章推荐
- UI初级之界面特殊处理技巧一
- UI初级之表视图UITableView自定义单元格
- ffmpeg: ‘UINT64_C’ was not declared in this scope (转)
- String详解, String和CharSequence区别, StringBuilder和StringBuffer的区别 (String系列之1)
- UI初级之常用UI控件UILabl 与 UIButton
- UI入门教程
- iOS开发:UITableView编辑——cell的删除和移动
- 聊聊并发——ConcurrentLinkedQueue的实现原理分析
- ui概述
- iOS-UILabel 自动换行
- Parameter 'uidList' not found. Available parameters are [list]
- Arduino DS18B20温度检测
- ecshop编辑器fckeditor换百度ueditor编辑器教程
- poj 2778 DNA Sequence (ac自动机+矩阵快速幂优化dp)
- String、StringBuilder
- 1099. Build A Binary Search Tree (30)
- this class is not key value coding-compliant for the key imageView的崩溃问题
- jquey.fullpage左右无缝轮播
- VBA 使用QueryTables 中文乱码的处理
- std::deque