#import "ViewController.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView ;
@property (nonatomic,strong)NSArray *dataArray ;
@property (nonatomic,strong) UIView *footView;
@end
@implementation ViewController
- (NSArray *)dataArray
{
if (nil == _dataArray) {
_dataArray = @[
@[@"个人资料",@"账号绑定"],
@[@"收货地址管理",@"实名认证管理",@"购物偏好设置"] ,
@[@"新消息设置"],
@[@"修改密码"],
@[@"清理缓存",@"关于聚美",@"日志上传"],
];
}
return _dataArray ;
}
-(UIView *)footView{
if (_footView == nil) {
_footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,0,self.view.frame.size.height*0.3)];
_footView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
}
return _footView;
}
#pragma mark - getter/setter
- (UITableView *)tableView
{
if (nil == _tableView) {
_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 70, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
//_tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
//_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellID"];
_tableView.dataSource = self ;
_tableView.delegate = self ;
_tableView.showsVerticalScrollIndicator=NO;//关闭上下滑动时的滑条
self.tableView.tableFooterView = self.footView;
}
return _tableView ;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
UIView *theView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)];
theView.backgroundColor=[UIColor whiteColor];
[self.view addSubview:theView];
UILabel *theLabel=[[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/4, 30, self.view.frame.size.width/2, 40)];
theLabel.text=@"设置";
theLabel.textAlignment=NSTextAlignmentCenter;
theLabel.font=[UIFont systemFontOfSize:5+self.view.frame.size.width/30];
[theView addSubview:theLabel];
NSLog(@"viewDidLoad");
[self.view addSubview:self.tableView] ;
UIButton *footButton=[[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width/5, self.view.frame.size.height/25, self.view.frame.size.width*3/5, 16+self.view.frame.size.height/32)];
footButton.backgroundColor=[UIColor whiteColor];
[footButton setTitle:@"退出登录" forState:UIControlStateNormal];
[footButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[footButton addTarget:self action:@selector(footButtonClick) forControlEvents:UIControlEventTouchUpInside];
footButton.titleLabel.font=[UIFont systemFontOfSize:5+self.view.frame.size.width/45];
//切圆角和设置弧度
footButton.layer.cornerRadius = footButton.frame.size.height/2;//半径大小
footButton.layer.masksToBounds = YES;//是否切割
[self.footView addSubview:footButton];
// Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.dataArray.count ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.dataArray[section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
self.tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID" forIndexPath:indexPath];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.text = self.dataArray[indexPath.section][indexPath.row];
cell.textLabel.font=[UIFont systemFontOfSize:5+self.view.frame.size.width/45];
cell.selectionStyle = UITableViewCellSelectionStyleNone;//点击cell时,cell的颜色不改变
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//每个cell的后面出现>
return cell ;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 20+self.view.frame.size.height/28;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSString *theStr;
switch (indexPath.section) {
case 0:
if (indexPath.row==0) {
NSLog(@"点击了个人资料");
theStr=@"个人资料";
} else if (indexPath.row==1) {
NSLog(@"账号绑定");
theStr=@"账号绑定";
}
break ;
case 1:
if (indexPath.row==0) {
NSLog(@"点击了收货地址管理");
theStr=@"收货地址管理";
} else if (indexPath.row==1) {
NSLog(@"点击了实名认证管理");
theStr=@"实名认证管理";
} else if (indexPath.row==2) {
NSLog(@"点击了购物偏好设置");
theStr=@"购物偏好设置";
}
break ;
case 2:
if (indexPath.row==0) {
NSLog(@"点击了新消息设置");
theStr=@"新消息设置";
}
break ;
case 3:
if (indexPath.row==0) {
NSLog(@"点击了修改密码");
theStr=@"修改密码";
}
break ;
case 4:
if (indexPath.row==0) {
NSLog(@"点击了清理缓存");
theStr=@"清理缓存";
} else if (indexPath.row==1) {
NSLog(@"点击了关于聚美");
theStr=@"关于聚美";
} else if (indexPath.row==2) {
NSLog(@"点击了日志上传");
theStr=@"日志上传";
}
break ;
default: break;
}
dispatch_async(dispatch_get_main_queue(), ^{
UILabel *theLabel=[[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width-self.view.frame.size.width/3)/2, self.view.frame.size.height/2, self.view.frame.size.width/3, 20+self.view.frame.size.height/35)];
theLabel.backgroundColor=[UIColor blackColor];
theLabel.layer.cornerRadius = theLabel.frame.size.height/7;
theLabel.clipsToBounds = YES;
theLabel.textColor=[UIColor whiteColor];
theLabel.alpha=0.8f;
theLabel.textAlignment=NSTextAlignmentCenter;
theLabel.font=[UIFont systemFontOfSize:5+self.view.frame.size.width/40];
theLabel.text=theStr;
[self.view addSubview:theLabel];
//设置动画
CATransition *transion=[CATransition animation];
transion.type=@"push";//动画方式
transion.subtype=@"fromTop";//设置动画从哪个方向开始
[theLabel.layer addAnimation:transion forKey:nil];//给layer添加动画。设置延时效果
//不占用主线程
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
[theLabel removeFromSuperview];
});//这句话的意思是1.5秒后,把label移出视图
});
}
//下面是设置分组的头部和底部间距
//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return self.view.frame.size.width/35;//section头部高度
}
//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
//设置头部颜色
UIView *headerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
headerView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
return headerView ;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0;//section底部高度
}
//section底部视图- (UIView
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *viewdd=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
viewdd.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0];
return viewdd;
}
-(void)footButtonClick
{
NSLog(@"点击了退出登录按钮");
NSLog(@"ddd~~");
dispatch_async(dispatch_get_main_queue(), ^{
UILabel *theLabel=[[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width-self.view.frame.size.width/3)/2, self.view.frame.size.height/2, self.view.frame.size.width/3, 20+self.view.frame.size.height/35)];
theLabel.backgroundColor=[UIColor blackColor];
theLabel.layer.cornerRadius = theLabel.frame.size.height/7;
theLabel.clipsToBounds = YES;
theLabel.textColor=[UIColor whiteColor];
theLabel.alpha=0.8f;
theLabel.textAlignment=NSTextAlignmentCenter;
theLabel.font=[UIFont systemFontOfSize:5+self.view.frame.size.width/40];
theLabel.text=@"退出登录";
[self.view addSubview:theLabel];
//设置动画
CATransition *transion=[CATransition animation];
transion.type=@"push";//动画方式
transion.subtype=@"fromTop";//设置动画从哪个方向开始
[theLabel.layer addAnimation:transion forKey:nil];//给layer添加动画。设置延时效果
//不占用主线程
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
[theLabel removeFromSuperview];
});//这句话的意思是1.5秒后,把label移出视图
});
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end