直接上代码,进行注释,更加明了
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// 设置标题
self.navigationItem.title = @"我的";
//设置视图的背景图片
UIImage *backG = [UIImage imageNamed:@"250"];
self.view.layer.contents = (__bridge id)(backG.CGImage);
#ifdef moreThanIOS7
//iOS7之后视图view从最顶点(0,0,0,0)开始。设置以后属性之后,与iOS7之前一致,从UINavigationBar下面开始
self.edgesForExtendedLayout = UIRectEdgeNone;
#endif
//设置头像以及最新轻博客图片及内容
[self headImageView];
//注意要设置属性为UITableViewStyleGrouped,才能是设置多个section,如果继承于UITableViewController,默认是UITableViewStylePlain,无法设置多个section
tableV = [[UITableView alloc]initWithFrame:CGRectMake(0,headImg.frame.size.height,ScreenWidth,Screenheight-headImg.frame.size.height-49) style:UITableViewStyleGrouped];
tableV.delegate = self;
tableV.dataSource = self;
//设置该属性,tableview无法滚动
// _tableV.scrollEnabled = NO;
[self.view addSubview:tableV];
tipsDic = [[NSDictionary alloc]initWithObjectsAndKeys:[NSArray arrayWithObjects:@"基本资料",@"证件认证",@"我的相册", nil],@"0",[NSArray arrayWithObjects:@"一对一授课",@"开班授课",@"授课区域",nil],@"1",[NSArray arrayWithObjects:@"我的信用",@"我的学生",nil],@"2",[NSArray arrayWithObjects:@"邀请入驻",@"账号设置",@"清除缓存",@"意见反馈",@"关于我们", nil],@"3", nil];
}
-(void)headImageView
{
CGFloat headHeight = 150;
headImg = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, ScreenWidth, headHeight)];
headImg.userInteractionEnabled = YES;
CGFloat porWidth = 60;
CGFloat porheight = 60;
CGFloat xGap = 20;
CGFloat yGap = 10;
portrait = [[UIImageView alloc]initWithFrame:CGRectMake(xGap, headHeight-porheight-yGap, porWidth, porheight)];
[headImg addSubview:portrait];
CGFloat wordwidth = ScreenWidth-porWidth-3*xGap;
CGFloat wordheight = 60;
words = [[UILabel alloc]initWithFrame:CGRectMake(xGap+porWidth+xGap,headHeight-wordheight-yGap, wordwidth, wordheight)];
words.backgroundColor = [UIColor clearColor];
words.textColor = [UIColor whiteColor];
[headImg addSubview:words];
[self.view addSubview:headImg];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section) {
case 0:
return 3;
break;
case 1:
return 3;
break;
case 2:
return 2;
break;
default:
return 5;
break;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 30.0f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
//设置每个section的headerview高度
return 10.0f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
//设置每个section的footerview高度
return 5.0f;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"information";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
//选区cell没有点击效果
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//固定图片的大小
CGSize itemsize = CGSizeMake(20, 20);
UIGraphicsBeginImageContext(itemsize);
CGRect imageRect = CGRectMake(0.0, 0.0, itemsize.width, itemsize.height);
[cell.imageView.image drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cell.imageView.image = [UIImage imageNamed:@"pic"];
cell.textLabel.text = [[tipsDic objectForKey:[NSString stringWithFormat:@"%ld",indexPath.section]] objectAtIndex:indexPath.row];
//cell右侧指示标志(右箭头标志)
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}