内容提要: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();
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();
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;
{
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) {
{
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]]];
_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;
//{
// checkImg.hidden = !checkImg.hidden;
//}
@end