作业要求如下:
具体设计步骤如下:
首先展示一下工程目录:
详细设计步骤如下:
首先新建plist文件,因为展示的所有信息都是一个用户的信息,而真正的程序不可能只有一个用户。所以说所有的用户是一个数组。根据对象设计plist文件如下:
设计图思路分析:
1、所有的用户是一个大的数组。每一个用户的所有信息是其中的一项。因为每一用户有多个属性,所以说用户是个字典。
2、因为一个用户有多篇日志,每篇日志都有几个相同的属性,所以说每篇日志是一个字典。一个用户有多篇日志,所以说一个用户字典要有一个所有日志属性的数组——此数组包含多项日志字典。服务客户和工作经历也与此类似。
3、因为个人信息比较多,所以把个人信息封装在一个formation字典中。
切记:建model模型时,需要字典转模型。每一个plist文件中的字典都需要新建一个对应的model模型。因为
要用到KVC中的setValuesForKry方法,所以每一个模型中的对象属性名都必须和plist文件中一一对应相同。
步骤二 新建Model 如下:
2.0 新建一个Log模型,表示每篇日志的属性:
编辑Log.h如下:
//
// Log.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import
@interface Log : NSObject
@property (nonatomic, strong) NSString *logTitle;
@property (nonatomic, strong) NSString *logImage;
@property (nonatomic, strong) NSString *text;
@property (nonatomic, strong) NSDate *logDate;
-(instancetype)initWithDict:(NSDictionary *) dict;
+(instancetype) logWithDict:(NSDictionary *) dict;
@end
编辑Log.m如下:
//
// Log.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "Log.h"
@implementation Log
-(instancetype)initWithDict:(NSDictionary *) dict
{
if (self = [super init]) {
// self.logTitle = dict[@"logTitle"];
// .........
[self setValuesForKeysWithDictionary:dict];
}
return self;
}
+(instancetype) logWithDict:(NSDictionary *) dict
{
return [[self alloc] initWithDict:dict];
}
@end
编辑WorkExper.h如下:
//
// WorkExper.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import
@interface WorkExper : NSObject
@property (nonatomic, assign) int beginDate;
@property (nonatomic, assign) int endDate;
@property (nonatomic, strong) NSString *company;
@property (nonatomic, strong) NSString *position;
-(instancetype) initWithDict:(NSDictionary *) dict;
+(instancetype) workExperWithDict:(NSDictionary *) dict;
@end
编辑WorkExper.m如下:
//
// WorkExper.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "WorkExper.h"
@implementation WorkExper
-(instancetype) initWithDict:(NSDictionary *) dict
{
if (self = [super init]) {
[self setValuesForKeysWithDictionary:dict];
}
return self;
}
+(instancetype) workExperWithDict:(NSDictionary *) dict
{
return [[self alloc] initWithDict:dict];
}
@end
编辑Formation.h如下:
//
// Formation.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import
@interface Formation : NSObject
@property (nonatomic, strong) NSString *realName;
@property (nonatomic, strong) NSString *address;
@property (nonatomic, strong) NSString *sex;
@property (nonatomic, strong) NSString *tools;
@property (nonatomic, strong) NSString *field;
@property (nonatomic, strong) NSString *businessDelegate;
-(instancetype) initWithDict:(NSDictionary *) dict;
+(instancetype) formationWithDict:(NSDictionary *) dict;
@end
编辑Formation.m如下:
//
// Formation.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "Formation.h"
@implementation Formation
-(instancetype) initWithDict:(NSDictionary *) dict
{
if (self = [super init]) {
[self setValuesForKeysWithDictionary:dict];
}
return self;
}
+(instancetype) formationWithDict:(NSDictionary *) dict
{
return [[self alloc] initWithDict:dict];
}
@end
编辑Server.h如下:
//
// Server.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/9.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import
@interface Server : NSObject
@property(nonatomic, strong) NSString *chinese;
@property (nonatomic, strong) NSString *english;
@property (nonatomic, strong) NSString *byTool;
-(instancetype) initWithDict:(NSDictionary *) dict;
+(instancetype) serverWithDict:(NSDictionary *)dict;
@end
编辑Server.m如下:
//
// Server.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/9.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "Server.h"
@implementation Server
-(instancetype) initWithDict:(NSDictionary *) dict
{
if (self = [super init])
{
[self setValuesForKeysWithDictionary:dict];
}
return self;
}
+(instancetype) serverWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}
@end
2.4 编辑表示一个用户的model:
编辑User.h如下:
//
// User.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import
#import "Log.h"
#import "WorkExper.h"
#import "Formation.h"
@interface User : NSObject
@property (nonatomic, strong) NSString *userName;
@property (nonatomic, strong) NSString *userIcon;
@property (nonatomic, strong) Formation * formation;
@property (nonatomic, strong) NSArray * workExpers;
@property (nonatomic, strong) NSString *honor;
@property (nonatomic, strong) NSArray *logs;
@property (nonatomic, strong) NSArray *servers;
-(instancetype) initWithDict:(NSDictionary *) dict;
+(instancetype) userWithDict:(NSDictionary *) dict;
@end
编辑User.m如下:
//
// User.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "User.h"
#import "Server.h"
@implementation User
-(instancetype) initWithDict:(NSDictionary *) dict
{
if (self = [super init])
{
[self setValuesForKeysWithDictionary:dict]; // 将不是字典的变量一一赋值
// 新建一个个人信息对象,取字典中的信息字典进行赋值初始化
NSDictionary *formDict = dict[@"formation"];
self.formation = [Formation formationWithDict:formDict];
// 新建一个存放工作经历model的可变数组
NSMutableArray *experMuArray = [NSMutableArray array];
// 遍历用户字典中的表示工作经历的数组转化为每个model存放在数组中
for(NSDictionary * experDict in dict[@"workExpers"])
{
// 新建一个用遍历的工作经历字典进行初始化WorkExper对象
WorkExper *experModel = [WorkExper workExperWithDict:experDict];
// 将初始化信息的model对象添加到experMuArray数组中
[experMuArray addObject:experModel];
}
self.workExpers = experMuArray; // 数组变量赋值
// 新建一个存放日志的可变数组
NSMutableArray *logMuArray = [NSMutableArray array];
// 遍历用户字典中表示日志的数组转化为每个日志model存放再数组中
for(NSDictionary *logDict in dict[@"logs"])
{
Log *lg = [Log logWithDict:logDict];
// 将model对象添加到可变数组中
[logMuArray addObject:lg];
}
self.logs = logMuArray; // 日志数组变量赋值
// 新建一个存放服务客户模型的 可变数组
NSMutableArray *serversMuArray = [NSMutableArray array];
// 遍历用户字典中表示服务客户的字典数组转化为每个客户模型再存放在数组中
for(NSDictionary *serDict in dict[@"servers"])
{
// 新建一个用遍历的客户字典进行初始化的Server对象
Server *ser = [Server serverWithDict:serDict];
[serversMuArray addObject:ser];
}
self.servers = serversMuArray;
}
return self;
}
+(instancetype) userWithDict:(NSDictionary *) dict
{
return [[self alloc] initWithDict:dict];
}
@end
编辑ReadFromPlist.h如下:
//
// ReadFromPlist.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import
@interface ReadFromPlist : NSObject
@property (nonatomic, strong) NSArray *arrays; // 存放所有的用户model
-(NSArray *) contentOfPlist;
+(NSArray *) contentOfPlist;
@end
编辑 ReadFromPlist.m如下:
//
// ReadFromPlist.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "ReadFromPlist.h"
#import "User.h"
@implementation ReadFromPlist
-(id) init
{
if (self = [super init]) { // 循环遍历,字典转模型
// 获取文件路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"users.plist" ofType:nil];
// 读取内容到数组
NSArray *usersDictArray = [NSArray arrayWithContentsOfFile:path];
// 创建存放所有用户model的可变数组
NSMutableArray *userModelArray = [NSMutableArray array];
// 遍历字典数组,将每一个用户字典转化为model存放在可变数组中
for(NSDictionary *userDict in usersDictArray)
{
// 将每一个用户字典转换成用户模型,并存放在可变数组中
User *userModel = [User userWithDict:userDict];
[userModelArray addObject:userModel];
}
self.arrays = userModelArray;
}
return self;
}
-(NSArray *) contentOfPlist
{
return self.arrays;
}
+(NSArray *) contentOfPlist
{
ReadFromPlist *readPlist = [[self alloc] init];
return readPlist.contentOfPlist;
}
@end
步骤四:为UILabel新建分类,增添方法使其根据内容大小和行距等属性自动确定UIlabel的高度
新建分类
编辑UILabel+LabelHH.h如下:
//
// UILabel+LabelHH.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import
@interface UILabel (LabelHH)
-(void)setDefaultStyleBy:(NSString *) text;
- (float) heightForStringByWidth:(float )width;
@end
编辑 UILabel+LabelHH.m如下:
//
// UILabel+LabelHH.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "UILabel+LabelHH.h"
#import "Header.h"
@implementation UILabel (LabelHH)
-(void)setDefaultStyleBy:(NSString *) text
{
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text];
//段落样式
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
// 设置段落行间距
paragraphStyle.lineSpacing = 10;
// 设置段落间距
paragraphStyle.paragraphSpacing = 20;
// 设置书写方向
paragraphStyle.baseWritingDirection = NSWritingDirectionLeftToRight;
// 设置对齐方式
paragraphStyle.alignment = NSTextAlignmentCenter;
// 设置首行缩进
paragraphStyle.firstLineHeadIndent = 40;
// 设置首行以外的其它行缩进
paragraphStyle.headIndent = 10;
// 设置每行容纳字符的宽度
paragraphStyle.tailIndent = self.frame.size.width- 20;
// 为富文本添加以上的段落属性
[attr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, text.length)];
// 设置富文本的字体
[attr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, text.length)];
// 设置富文本的字体颜色
[attr addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xa0a0a0) range:NSMakeRange(0, text.length)];
self.numberOfLines = 0;
self.attributedText = attr;
CGFloat x = self.frame.origin.x;
CGFloat y = self.frame.origin.y;
CGFloat wid = self.frame.size.width;
CGFloat hig = [self heightForStringByWidth:wid];
self.frame = CGRectMake(x, y, wid, hig);
self.attributedText = attr;
}
- (float) heightForStringByWidth:(float )width{
CGSize sizeToFit = [self sizeThatFits:CGSizeMake(width, MAXFLOAT)];
return sizeToFit.height;
}
@end
步骤五:编辑AppDelegate.m 设计整体布局:
//
// AppDelegate.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "AppDelegate.h"
#import "LogListViewController.h"
#import "UserFormationViewController.h"
#import "ReadFromPlist.h"
#import "User.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
// 新建tabBar控制器作为窗体的根视图控制器
UITabBarController *tab = [[UITabBarController alloc] init];
tab.tabBar.barTintColor = [UIColor clearColor];
self.window.rootViewController = tab;
// 新建第一个视图控制器来初始化第一个导航控制器
LogListViewController *logListVC = [[LogListViewController alloc] init];
UINavigationController * logNaviVC = [[UINavigationController alloc] initWithRootViewController:logListVC];
logNaviVC.navigationBar.barTintColor = [UIColor blackColor];
logNaviVC.tabBarItem.title = @"日志";
logNaviVC.tabBarItem.image = [UIImage imageNamed:@"btn_日志_n"];
logNaviVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"btn_日志_d"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
// 设置选中和正常状态下的字体特性
[logNaviVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor redColor]} forState:UIControlStateSelected];
[logNaviVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]} forState:UIControlStateNormal];
// 读取日志篇数
NSArray *readPl = [ReadFromPlist contentOfPlist]; // 所有用户的数据
User * firsrUserForm = readPl[0]; // 取出第一个用户的所有信息
NSArray *logsArray = firsrUserForm.logs;
logNaviVC.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d篇",logsArray.count];
// 新建第二个视图控制器来初始化第二个导航控制器
UserFormationViewController *formVC = [[UserFormationViewController alloc] init];
formVC.user = firsrUserForm;
UINavigationController *formNaviVC = [[UINavigationController alloc] initWithRootViewController:formVC];
formNaviVC.tabBarItem.title = @"关于";
formNaviVC.tabBarItem.image = [UIImage imageNamed:@"btn_关于_n"];
formNaviVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"btn_关于_d"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// 设置选中和正常状态下字体的颜色
[formNaviVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor redColor]} forState:UIControlStateSelected];
[formNaviVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]} forState:UIControlStateNormal];
tab.viewControllers = @[logNaviVC,formNaviVC];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
6.0 自定义继承于UITabViewCell的单元格如下:
编辑TableViewCellLog.h如下:
//
// TableViewCellLog.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import
#import "Header.h"
@class Log;
@interface TableViewCellLog : UITableViewCell
@property(nonatomic, strong) Log *logOfCell;
@property (nonatomic, strong) UIImageView *cellImg;
@property (nonatomic, strong) UILabel *cellTitle;
@property (nonatomic, strong) UILabel *cellDate;
@end
编辑 TableViewCellLog.m如下:
//
// TableViewCellLog.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "TableViewCellLog.h"
#import "Log.h"
@implementation TableViewCellLog
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) { // 初始化相当于在单元格内加进了组件并分配的空间
self.backgroundColor = [UIColor blackColor];
// 将ImageView添加到cell
UIImageView *imgv = [[UIImageView alloc] init];
[self.contentView addSubview:imgv];
self.cellImg = imgv;
// 将UILabel添加到cell
UILabel *label1 = [[UILabel alloc] init];
[self.contentView addSubview:label1];
self.cellTitle = label1;
UILabel *label2 = [[UILabel alloc] init];
[self.contentView addSubview:label2];
self.cellDate = label2;
}
return self;
}
// 必须重写logOfCell属性的setter方法
-(void)setLogOfCell:(Log *)logOfCell
{
_logOfCell = logOfCell;
[self settingData]; // 设置数据
[self settingFrame]; // 设置位置和大小
}
-(void)settingData
{
self.cellImg.image = [UIImage imageNamed:_logOfCell.logImage];
self.cellTitle.text = _logOfCell.logTitle;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd";
self.cellDate.text = [formatter stringFromDate:_logOfCell.logDate];
}
-(void ) settingFrame
{
self.cellImg.frame = CGRectMake(10, 10, 70, 70);
self.cellTitle.frame = CGRectMake(90, 32, 100, 20);
[self.cellTitle setFont:[UIFont systemFontOfSize:14]];
self.cellTitle.textColor = UIColorFromRGB(0xa0a0a0);
self.cellDate.frame = CGRectMake(90, 61, 100, 10);
[self.cellDate setFont:[UIFont systemFontOfSize:9]];
self.cellDate.textColor = UIColorFromRGB(0xa0a0a0);
}
- (void)awakeFromNib
{
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
}
@end
6.1 自定义分割线组件如下:
编辑SeparatorView.h如下:
//
// SeparatorView.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/9.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import
@interface SeparatorView : UIView
@property (nonatomic, strong) UIView *sep;
@end
编辑 SeparatorView.m如下:
//
// SeparatorView.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/9.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "SeparatorView.h"
@implementation SeparatorView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
CGFloat x = frame.origin.x;
CGFloat y = frame.origin.y;
CGFloat wid = frame.size.width;
CGFloat hig = frame.size.height;
self.sep = [[UIView alloc] initWithFrame:CGRectMake(x, y, wid, hig)];
self.backgroundColor = [UIColor darkGrayColor];
[self addSubview:self.sep];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
6.2 自定义 含有两个文本UILabel的控件如下:
编辑BarView.h如下:
//
// BarView.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/9.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import
@interface BarView : UIView
@property (nonatomic, strong) UILabel *lblLeft;
@property (nonatomic, strong) UILabel *lblRight;
- (id)initWithFrame:(CGRect)frame leftToRight:(CGFloat )bl;
-(void) setLeftBoldLabel:(UILabel *) label andText:(NSString *) text;
-(void) setContentLabel:(UILabel *)label andText:(NSString *) text;
@end
编辑 BarView.m如下:
//
// BarView.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/9.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "BarView.h"
#import "Header.h"
@implementation BarView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (id)initWithFrame:(CGRect)frame leftToRight:(CGFloat )bl
{
self = [super initWithFrame:frame];
if (self) {
self.lblLeft = [[UILabel alloc] initWithFrame:CGRectMake(20, frame.origin.y, frame.size.width*bl, 31)];
self.lblRight = [[UILabel alloc] initWithFrame:CGRectMake(self.lblLeft.frame.origin.x+self.lblLeft.frame.size.width, self.lblLeft.frame.origin.y, frame.size.width*(1-bl), 31)];
[self setContentLabel:self.lblLeft andText:nil];
[self setContentLabel:self.lblRight andText:nil];
[self addSubview:self.lblLeft];
[self addSubview:self.lblRight];
}
return self;
}
-(void) setLeftBoldLabel:(UILabel *) label andText:(NSString *) text
{
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
label.text = text;
label.textColor = UIColorFromRGB(0xa0a0a0);
label.textAlignment = NSTextAlignmentLeft;
}
-(void) setContentLabel:(UILabel *)label andText:(NSString *) text
{
label.font = [UIFont systemFontOfSize:14];
label.text = text;
label.textColor = UIColorFromRGB(0xa0a0a0);
label.textAlignment = NSTextAlignmentLeft;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
6.3自定义含有三个UILabel的控件,继承于BarVIew如下:
编辑BarViewAndSon.h如下:
//
// BarViewAndSon.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/9.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "BarView.h"
@interface BarViewAndSon : BarView
@property (nonatomic, strong) UILabel *lblSonOfSon;
@end
编辑 BarViewAndSon.m如下:
//
// BarViewAndSon.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/9.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "Header.h"
@implementation BarViewAndSon
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (id)initWithFrame:(CGRect)frame leftToRight:(CGFloat )bl
{
if (self = [super initWithFrame:frame leftToRight:bl])
{
self.lblLeft.frame = CGRectMake(20, 11, frame.size.width*bl, frame.size.height/2);
self.lblRight.frame = CGRectMake(self.lblLeft.frame.origin.x+self.lblLeft.frame.size.width, self.lblLeft.frame.origin.y, frame.size.width*(1-bl), frame.size.height/2);
self.lblSonOfSon = [[UILabel alloc] initWithFrame:CGRectMake(self.lblLeft.frame.origin.x, self.lblLeft.frame.origin.y+self.lblLeft.frame.size.height+5, WIDTH, 20)];
[self setContentLabel:self.lblSonOfSon andText:nil];
[self addSubview:self.lblSonOfSon];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
编辑AppDelegate.m如下:
//
// AppDelegate.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "AppDelegate.h"
#import "LogListViewController.h"
#import "UserFormationViewController.h"
#import "ReadFromPlist.h"
#import "User.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
// 新建tabBar控制器作为窗体的根视图控制器
UITabBarController *tab = [[UITabBarController alloc] init];
tab.tabBar.barTintColor = [UIColor clearColor];
self.window.rootViewController = tab;
// 新建第一个视图控制器来初始化第一个导航控制器
LogListViewController *logListVC = [[LogListViewController alloc] init];
UINavigationController * logNaviVC = [[UINavigationController alloc] initWithRootViewController:logListVC];
logNaviVC.navigationBar.barTintColor = [UIColor blackColor];
logNaviVC.tabBarItem.title = @"日志";
logNaviVC.tabBarItem.image = [UIImage imageNamed:@"btn_日志_n"];
logNaviVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"btn_日志_d"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
// 设置选中和正常状态下的字体特性
[logNaviVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor redColor]} forState:UIControlStateSelected];
[logNaviVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]} forState:UIControlStateNormal];
// 读取日志篇数
NSArray *readPl = [ReadFromPlist contentOfPlist]; // 所有用户的数据
User * firsrUserForm = readPl[0]; // 取出第一个用户的所有信息
NSArray *logsArray = firsrUserForm.logs;
logNaviVC.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d篇",logsArray.count];
// 新建第二个视图控制器来初始化第二个导航控制器
UserFormationViewController *formVC = [[UserFormationViewController alloc] init];
formVC.user = firsrUserForm;
UINavigationController *formNaviVC = [[UINavigationController alloc] initWithRootViewController:formVC];
formNaviVC.tabBarItem.title = @"关于";
formNaviVC.tabBarItem.image = [UIImage imageNamed:@"btn_关于_n"];
formNaviVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"btn_关于_d"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// 设置选中和正常状态下字体的颜色
[formNaviVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor redColor]} forState:UIControlStateSelected];
[formNaviVC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]} forState:UIControlStateNormal];
tab.viewControllers = @[logNaviVC,formNaviVC];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
步骤八:设计控制器
8.0 新建显示日志列表的控制器如下:
编辑LogListViewController.h
//
// LogListViewController.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import
@class User;
@interface LogListViewController : UIViewController
@property (nonatomic, strong) UITableView *tabView;
@property (nonatomic, strong) User *user;
@end
编辑LogListViewController.m
//
// LogListViewController.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "Header.h"
@interface LogListViewController ()
@end
@implementation LogListViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void) userData
{
NSArray *userModelsArray = [ReadFromPlist contentOfPlist];
// 假设当前是第一个用户
self.user = userModelsArray[0];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// 隐藏导航栏
self.navigationController.navigationBar.hidden = YES;
[self userData];
// 新建一个UITabView组件
self.tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStyleGrouped];
self.tabView.rowHeight = 90; // 设置单元格高度
self.tabView.delegate = self; // 设置当前控制器为数据源对象和代理实现类
self.tabView.dataSource = self;
self.tabView.backgroundColor = [UIColor blackColor];
// 为UITabView添加头视图
UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
UILabel *head = [[UILabel alloc] initWithFrame:CGRectMake(10, 11, WIDTH-10, 50)];
head.text = self.user.userName;
head.textColor = UIColorFromRGB(0xa0a0a0);
head.textAlignment = NSTextAlignmentLeft;
[head setFont:[UIFont systemFontOfSize:12]];
[headView addSubview:head];
self.tabView.tableHeaderView = headView;
[self.view addSubview:self.tabView];
}
-(void) viewWillAppear:(BOOL)animated
{
[self viewDidLoad];
}
// 返回组数
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// 返回每一组有多少行
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"%d",self.user.logs.count);
return self.user.logs.count;
}
// 返回每一行单元格的内容
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ID = @"user_id";
// 先从缓存池中寻找有重用ID的单元格
TableViewCellLog *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
cell = [[TableViewCellLog alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
// 获取日志数组
NSArray *logsArray = self.user.logs;
Log * lg = logsArray[indexPath.row];
NSLog(@"%@",lg.logImage);
cell.logOfCell = lg;
return cell;
}
// 实现代理中的方法,监听选中单元格时的事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *logsArray = self.user.logs;
Log *lg = logsArray[indexPath.row];
LogDetailViewController *logDetilVC = [[LogDetailViewController alloc] init];
logDetilVC.log = lg;
[self.navigationController pushViewController:logDetilVC animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
8.1 新建显示日志详情的控制器如下:
编辑LogDetailViewController.h
//
// LogDetailViewController.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import
@class Log;
@interface LogDetailViewController : UIViewController
@property (nonatomic, strong) Log *log;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UILabel *lblText;
@property (nonatomic, strong) UILabel *lblTitle;
@property (nonatomic, strong) UILabel *lblDate;
@property (nonatomic, strong ) UIImageView *imgv;
@end
编辑 LogDetailViewController.m
//
// LogDetailViewController.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "Header.h"
@interface LogDetailViewController ()
@property (nonatomic, assign) BOOL show;
@end
@implementation LogDetailViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor blackColor]];
// self.navigationController.navigationBar.hidden = NO; // 显示导航条
self.navigationController.navigationBar.hidden = NO;
self.tabBarController.tabBar.hidden = NO;
// 设置返回按钮
UIButton *btnBack = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 22, 22)];
[btnBack setBackgroundImage:[UIImage imageNamed:@"btn_返回_n"] forState:UIControlStateNormal];
[btnBack addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:btnBack];
self.navigationItem.leftBarButtonItem = item;
// 新建UIlabel组件显示正文内容
self.lblText = [[UILabel alloc] initWithFrame:CGRectMake(0, 60, WIDTH, 20)];
[self.lblText setDefaultStyleBy:self.log.text]; // 给组件设置内容并调整大小
// 新建UIlabel组件显示标题
self.lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, WIDTH, 20)];
self.lblTitle.textAlignment = NSTextAlignmentLeft;
self.lblTitle.textColor = UIColorFromRGB(0xa0a0a0);
[self.lblTitle setFont:[UIFont systemFontOfSize:20]];
self.lblTitle.text = self.log.logTitle;
// 新建日志时间
self.lblDate = [[UILabel alloc] initWithFrame:CGRectMake(10, self.lblTitle.frame.origin.y+self.lblTitle.frame.size.height, 100, 20)];
self.lblDate.textAlignment = NSTextAlignmentLeft;
self.lblDate.textColor = UIColorFromRGB(0xa0a0a0);
[self.lblDate setFont:[UIFont systemFontOfSize:12]];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd";
self.lblDate.text =[formatter stringFromDate:self.log.logDate];
// 新建UIImageView组件
self.imgv = [[UIImageView alloc] initWithFrame:CGRectMake(10, self.lblText.frame.size.height+self.lblText.frame.origin.y+20, WIDTH-20, HEIGHT/2.5)];
self.imgv.image = [UIImage imageNamed:self.log.logImage];
// 添加UIScrollView组件作为容器来容纳日志内容
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
self.scrollView.backgroundColor = [UIColor blackColor];
[self.scrollView addSubview:self.lblText];
[self.scrollView addSubview:self.lblTitle];
[self.scrollView addSubview:self.imgv];
[self.scrollView addSubview:self.lblDate];
self.scrollView.contentSize = CGSizeMake(0, self.lblText.frame.size.height+self.imgv.frame.size.height);
// 为UIScrollView添加手势类监听
UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(event)];
[tapRec setNumberOfTapsRequired:1];
[tapRec setNumberOfTouchesRequired:1];
[self.scrollView addGestureRecognizer:tapRec];
self.scrollView.contentInset = UIEdgeInsetsMake(100, 0, 200, 0);
[self.scrollView touchesBegan:nil withEvent:nil];
//self.scrollView.contentOffset = CGPointMake(0, -100);
[self.view addSubview:self.scrollView];
self.show = NO;
}
-(void)event
{
NSLog(@"++++++");
if (self.show == NO) {
self.navigationController.navigationBar.hidden = NO;
self.tabBarController.tabBar.hidden = NO;
self.show = YES;
}
else
{
self.navigationController.navigationBar.hidden = YES;
self.tabBarController.tabBar.hidden = YES;
self.show = NO;
}
}
-(void)back
{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(void) viewWillAppear:(BOOL)animated
{
[self viewDidLoad];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
编辑UserFormationViewController.h
//
// UserFormationViewController.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import
@class SeparatorView;
@class User;
@interface UserFormationViewController : UIViewController
@property (nonatomic, strong) UIScrollView *scrollview;
@property (nonatomic, strong) User *user;
@property (nonatomic , strong) UIView *uvHead; // 头像部分
@property (nonatomic, strong) UIView *uvBaseForm; // 基本信息部分
@property (nonatomic, strong) UIView *uvWorkExper; // 工作经历部分
@property (nonatomic, strong) UIView * uvServers; //服务客户部分
@property (nonatomic, strong) UILabel *lblhonor;
@end
编辑UserFormationViewController.m
//
// UserFormationViewController.m
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#import "Header.h"
@interface UserFormationViewController ()
@property (nonatomic, assign) BOOL show;
@end
@implementation UserFormationViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
//==============设置第一部分信息——头像信息=========================
-(void) viewOne
{
// 设置用户名
self.view.backgroundColor = [UIColor blackColor];
UILabel * lblName = [[UILabel alloc] initWithFrame:CGRectMake(10, 11, WIDTH-20, 30)];
lblName.text = self.user.userName;
lblName.textAlignment = NSTextAlignmentLeft;
lblName.textColor = UIColorFromRGB(0xa0a0a0);
[lblName setFont: [UIFont systemFontOfSize:18]];
// 设置用户头像
UIImageView *imgv = [[UIImageView alloc] initWithFrame:CGRectMake(10, lblName.frame.origin.y+lblName.frame.size.height+20, 227*0.5, 304*0.5)];
imgv.backgroundColor = [UIColor darkGrayColor];
imgv.image = [UIImage imageNamed:self.user.userIcon];
UILabel *lblForm = [[UILabel alloc] initWithFrame:CGRectMake(20,imgv.frame.origin.y+imgv.frame.size.height+20, WIDTH-20, 20)];
[self titleLabel:lblForm andText:@"基本信息"];
SeparatorView *sep = [[SeparatorView alloc] initWithFrame:CGRectMake(0, lblForm.frame.origin.y+lblForm.frame.size.height+10, WIDTH, 1.2)];
self.uvHead = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, imgv.frame.origin.y+imgv.frame.size.height+40)];
[self.uvHead addSubview:lblName];
[self.uvHead addSubview:imgv];
[self.uvHead addSubview:sep];
[self.uvHead addSubview:lblForm];
}
// ==================设置第二部分信息——基本信息======================
-(void)viewTwo
{
BarView *bar = [[BarView alloc] initWithFrame:CGRectMake(0, 10, WIDTH, 31) leftToRight:0.3];
[bar setLeftBoldLabel:bar.lblLeft andText:@"真实姓名"];
[bar setContentLabel:bar.lblRight andText:self.user.formation.realName];
BarView *bar2 = [[BarView alloc] initWithFrame:CGRectMake(0, 31, WIDTH,31) leftToRight:0.3];
[bar2 setLeftBoldLabel:bar2.lblLeft andText:@"所在区域"];
[bar2 setContentLabel:bar2.lblRight andText:self.user.formation.address];
BarView *bar3 = [[BarView alloc] initWithFrame:CGRectMake(0, 50, WIDTH, 31) leftToRight:0.3];
[bar3 setLeftBoldLabel:bar3.lblLeft andText:@"性别"];
[bar3 setContentLabel:bar3.lblRight andText:self.user.formation.sex];
BarView *bar4 = [[BarView alloc] initWithFrame:CGRectMake(0, 70, WIDTH, 31) leftToRight:0.3];
[bar4 setLeftBoldLabel:bar4.lblLeft andText:@"创作工具"];
[bar4 setContentLabel:bar4.lblRight andText:self.user.formation.tools];
BarView *bar5 = [[BarView alloc] initWithFrame:CGRectMake(0, 90, WIDTH, 50) leftToRight:0.3];
[bar5 setLeftBoldLabel:bar5.lblLeft andText:@"擅长领域"];
[bar5 setContentLabel:bar5.lblRight andText:self.user.formation.field];
BarView *bar6 = [[BarView alloc] initWithFrame:CGRectMake(0, 110, WIDTH, 50) leftToRight:0.3];
[bar6 setLeftBoldLabel:bar6.lblLeft andText:@"商业委托"];
[bar6 setContentLabel:bar6.lblRight andText:self.user.formation.businessDelegate];
UILabel *lblForm = [[UILabel alloc] initWithFrame:CGRectMake(20,285, WIDTH-20, 20)];
[self titleLabel:lblForm andText:@"工作经历"];
SeparatorView *sep = [[SeparatorView alloc] initWithFrame:CGRectMake(0,320, WIDTH, 1.2)];
// 新建存放第二部分内容的容器
self.uvBaseForm = [[UIView alloc] initWithFrame:CGRectMake(0, self.uvHead.frame.origin.y+self.uvHead.frame.size.height, WIDTH, 31*6+152)];
[self.uvBaseForm addSubview:bar];
[self.uvBaseForm addSubview:bar2];
[self.uvBaseForm addSubview:bar3];
[self.uvBaseForm addSubview:bar4];
[self.uvBaseForm addSubview:bar5];
[self.uvBaseForm addSubview:bar6];
[self.uvBaseForm addSubview:lblForm];
[self.uvBaseForm addSubview:sep];
}
// ==================设置第三部分信息——工作经历信息======================
-(void)viewThree
{
// 新建第三部分内容的容器
self.uvWorkExper = [[UIView alloc] initWithFrame:CGRectMake(0, self.uvBaseForm.frame.origin.y+self.uvBaseForm.frame.size.height, WIDTH, 400)];
// 遍历数组,取出工作经历
for(WorkExper * work in self.user.workExpers)
{
int index = [self.user.workExpers indexOfObject:work];
BarViewAndSon *bs = [[BarViewAndSon alloc] initWithFrame:CGRectMake(0, 10+65*index, WIDTH, 31) leftToRight:0.3];
NSString *strLeft = [NSString stringWithFormat:@"%d-%d",work.beginDate,work.endDate];
[bs setContentLabel:bs.lblLeft andText:strLeft];
[bs setContentLabel:bs.lblRight andText:work.company];
NSString *strDown = [NSString stringWithFormat:@"职位: %@",work.position];
[bs setContentLabel:bs.lblSonOfSon andText:strDown];
[self.uvWorkExper addSubview:bs];
}
// 遍历数组后重新修改当前容器的大小
self.uvWorkExper.frame = CGRectMake(0, self.uvBaseForm.frame.origin.y+self.uvBaseForm.frame.size.height, WIDTH, self.user.workExpers.count*65+60);
UILabel *lblForm = [[UILabel alloc] initWithFrame:CGRectMake(20,360, WIDTH-20, 20)];
[self titleLabel:lblForm andText:@"服务客户"];
SeparatorView *sep = [[SeparatorView alloc] initWithFrame:CGRectMake(0,400, WIDTH, 1.2)];
[self.uvWorkExper addSubview:sep];
[self.uvWorkExper addSubview:lblForm];
}
// ==================设置第四部分信息——服务客户信息======================
-(void)viewFour
{
self.uvServers = [[UIView alloc] initWithFrame:CGRectMake(0, self.uvWorkExper.frame.origin.y+self.uvWorkExper.frame.size.height+10, WIDTH, 720)];
// 遍历数组,取出服务客户
for(Server * ser in self.user.servers)
{
int index = [self.user.servers indexOfObject:ser];
BarViewAndSon *bs = [[BarViewAndSon alloc] initWithFrame:CGRectMake(0, 10+65*index, WIDTH, 31) leftToRight:0.3];
[bs setContentLabel:bs.lblLeft andText:ser.english];
[bs setContentLabel:bs.lblRight andText:ser.chinese];
[bs setContentLabel:bs.lblSonOfSon andText:ser.byTool];
[self.uvServers addSubview:bs];
}
UILabel *lblForm = [[UILabel alloc] initWithFrame:CGRectMake(20,680, WIDTH-20, 20)];
[self titleLabel:lblForm andText:@"所获荣誉"];
SeparatorView *sep = [[SeparatorView alloc] initWithFrame:CGRectMake(0,720, WIDTH, 1.2)];
// 重新修改第四部分信息的容器高度
self.uvServers.frame = CGRectMake(0, self.uvWorkExper.frame.origin.y+self.uvWorkExper.frame.size.height+10, WIDTH, self.user.servers.count*65+60);
[self.uvServers addSubview:sep];
[self.uvServers addSubview:lblForm];
}
// ==================设置第五部分信息——获取荣誉信息======================
-(void)viewFive
{
self.lblhonor = [[UILabel alloc] initWithFrame:CGRectMake(0, self.uvServers.frame.origin.y+self.uvServers.frame.size.height+28, WIDTH, 30)];
[self.lblhonor setDefaultStyleBy:self.user.honor];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor blackColor]];
self.navigationController.navigationBar.hidden = YES;
[self viewOne];
[self viewTwo];
[self viewThree];
[self viewFour];
[self viewFive];
// 新建UIScrollView组件
self.scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
[self.scrollview addSubview:self.uvHead]; // 添加存放第一部分内容的容器
[self.scrollview addSubview:self.uvBaseForm]; // 添加存放第二部分内容的容器
[self.scrollview addSubview:self.uvWorkExper]; // 添加存放第三部分内容的容器
[self.scrollview addSubview:self.uvServers]; // 添加存放第四部分内容的容器
[self.scrollview addSubview:self.lblhonor];
self.scrollview.contentSize = CGSizeMake(0, self.lblhonor.frame.origin.y+self.lblhonor.frame.size.height);
//为UIscrollView组建添加手势
UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(event)];
[tapRec setNumberOfTapsRequired:1];
[tapRec setNumberOfTouchesRequired:1];
[self.scrollview addGestureRecognizer:tapRec];
[self.view addSubview:self.scrollview];
}
-(void) titleLabel:(UILabel *) label andText:(NSString *) text
{
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
label.text = text;
label.textColor = UIColorFromRGB(0xa0a0a0);
label.textAlignment = NSTextAlignmentLeft;
}
-(void) contentLabel:(UILabel *)label andText:(NSString *) text
{
label.font = [UIFont systemFontOfSize:12];
label.text = text;
label.textColor = UIColorFromRGB(0xa0a0a0);
label.textAlignment = NSTextAlignmentLeft;
}
-(void)event
{
NSLog(@"++++++");
if (self.show == NO) {
self.tabBarController.tabBar.hidden = NO;
self.show = YES;
}
else
{
self.tabBarController.tabBar.hidden = YES;
self.show = NO;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
步骤九:新建一个head.h的头文件,将常用的宏定义和每个类的头文件写进去,然后去掉每个类中导入的各个头文件的import,只需导入header.h即可。
编辑header.h如下:
//
// Header.h
// 日志信息之UITabBar与UINavigationBar的结合使用
//
// Created by apple on 15/9/8.
// Copyright (c) 2015年 LiuXun. All rights reserved.
//
#ifndef _____UITabBar_UINavigationBar______Header_h
#define _____UITabBar_UINavigationBar______Header_h
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define BOLDFONT [UIFont fontWithName:@"Helvetica-Bold" size:15]
#import "UILabel+LabelHH.h"
#import "ReadFromPlist.h"
#import "Log.h"
#import "WorkExper.h"
#import "Formation.h"
#import "User.h"
#import "Server.h"
#import "TableViewCellLog.h"
#import "LogListViewController.h"
#import "UserFormationViewController.h"
#import "LogDetailViewController.h"
#import "SeparatorView.h"
#import "BarView.h"
#import "BarViewAndSon.h"
#endif
运行结果如下:
单击隐藏导航栏和工具栏再单击又显示
返回界面后显示个人信息如下,个人信息同样是。单击隐藏,单击显示,,,