iOS项目实战02

2016-07-03  本文已影响0人  linguosong

修改插件:查找插件 -> 插件路径(不能记) -> Xcode插件开发 -> 查看插件代码 -> 搜索install -> 就能找到插件安装路径

1. 懒加载机制

 UIViewController的view,也是懒加载
- (UIView *)view
{
    if (_view == nil) {
        [self loadView];
        [self viewDidLoad];
    }
    return _view;
}

2. tabBar上的按钮问题


// 为什么要加载类到内存
// 程序一启动,会自动把所有的类加载进内存
// 什么时候调用:当类加载到内存的时候会调用
// 调用一次
+ (void)load
{ 
    // 设置文字颜色
    // 获取所有UITabBarItem外观
    UITabBarItem *item = [UITabBarItem appearance];
    // 文字颜色为黑色
    // 字典描述文字信息
    // Bug:在选中状态下设置文字字体不成功,应该在正常状态下去设置文字字体
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    attr[NSForegroundColorAttributeName] = [UIColor blackColor];
    // 设置选中状态下文字颜色
    [item setTitleTextAttributes:attr forState:UIControlStateSelected];
    
    // 设置正常状态下文字字体
    NSMutableDictionary *attrNor = [NSMutableDictionary dictionary];
    attrNor[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:attrNor forState:UIControlStateNormal];
}

3.设置导航条内容


UIView *containerView = [[UIView alloc] initWithFrame:btn.bounds];
    [containerView addSubview:btn];
    
    return [[UIBarButtonItem alloc] initWithCustomView:containerView];
    UIBarButtonItem *setting =  [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"mine-setting-icon"] highImage:[UIImage imageNamed:@"mine-setting-icon-click"] target:self action:@selector(settingClick)];

    UIBarButtonItem *night =  [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"mine-moon-icon"] selImage:[UIImage imageNamed:@"mine-moon-icon-click"] target:self action:@selector(nightClick:)];
    
    self.navigationItem.rightBarButtonItems = @[setting,night];
    
}
- (void)nightClick:(UIButton *)btn
{
    btn.selected = !btn.selected;    
}
[UIColor colorWithRed:((float)arc4random_uniform(256) / 255.0) green:((float)arc4random_uniform(256) / 255.0) blue:((float)arc4random_uniform(256) / 255.0) alpha:1.0];```
上一篇下一篇

猜你喜欢

热点阅读