爱限免项目第一天知识点回顾

2016-01-05  本文已影响22人  信徒_lh
NSString *plistPath = [[NSBundle mainBundle]pathForResource:@"controllers" ofType:@"plist"];
NSArray *plistArray = [NSSArray arrayWithContentsOfFile:plistPath];
Class class = NSClassFromString(className);
//AppListViewController为分栏控制器中所有视图控制器的父类,所以在此可以通过父类对象创建对象(不看对象看指针)
AppListViewController *appListVC = [[class alloc] init];
UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:appListVC];
//iconName为之前的数组中取出的值
//第二个参数是一个枚举值,系统默认呈现的是(tintColor渲染色)所以要将其设置为原始图片。
UIImage *normalImage = [UIImage imageNamed:iconName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_press",iconName]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        navi.tabBarItem = [[UITabBarItem alloc]initWithTitle:title image:normalImage selectedImage:selectedImage];
//获取UITabBar 并自定义图片
    UITabBar *tabBar = self.tabBar;
    //设置背景图片
    [tabBar setBackgroundImage:[UIImage imageNamed:@"tabbar_bg"]];
 //获取所有的导航控制器
    NSArray *naviControllers = self.viewControllers;
    for (UINavigationController *navi in naviControllers) {
        //获取UINavigationBar
        UINavigationBar *naviBar = navi.navigationBar;
        //设置导航条背景图片 图片高度如果不为44会自动重绘(所以高度最好为44×)
        [naviBar setBackgroundImage:[UIImage imageNamed:@"navigationbar"] forBarMetrics:UIBarMetricsDefault];
    }
//创建表格式图步骤基本一直就不写了,关于请求数据和前面网络复习步骤也是一直的在这里主要提两点
//1.用拼接好了的字符串创建统一资源定位符
//NSRequestURL属性,由于每个视图控制器请求数据是得统一资源定位符并不相同,所以在基类中创建一个这样的属性让每个子类继承并重新初始化该属性的值(是一个Define文件中定义的宏)使每个视图控制器上请求到得数据各不一样。
NSString *url = [NSString stringWithFormat:self.requestURL,page,self.searchStr?:@""];
//2.在使用Block的时候,里面的操作相当于一次拷贝,所以在里面使用指针会导致其引用计数 +1 所以必须使用弱引用
    __weak typeof(self) weakSelf = self;
self.appListTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf requestDataWithPage:1];
    }];
-(void)customNaviItemTitle:(NSString *)title{
// 定制UINavigationItem 的标题视图titleView
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = [UIFont systemFontOfSize:20];
    titleLabel.textColor = [UIColor purpleColor];
    //设置文字
    titleLabel.text = title;
    //设置导航项的标题
    self.navigationItem.titleView = titleLabel;
}
-(void)customTabBarButtonTitle:(NSString *)title image:(NSString *)imageName target:(id)target action:(SEL)seletor isLeft:(BOOL)isLeft{
UIButton *button = [ UIButton buttonWithType:UIButtonTypeSystem];
    [button setBackgroundImage:[UIImage imageNamed:imageName] forState:0];
    [button setTitle:title forState:0];
    [button addTarget:target action:seletor forControlEvents:UIControlEventTouchDown];
    button.frame = CGRectMake(0, 0, 44, 30);
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    
    //判断是否为左侧按钮 用自定义按钮定制导航项 如果左右两边都有导航项可以将该方法调用两次
    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    if (isLeft) {
        self.navigationItem.leftBarButtonItem = buttonItem;
    }
    else{
        self.navigationItem.rightBarButtonItem = buttonItem;
    }
}
上一篇 下一篇

猜你喜欢

热点阅读