【iOS】兴趣小组demo

继上次用Objective_C类的方式实现的兴趣小组,以iOS界面的方法再次呈现一次。

作为初学者,方法的选择实现较简单,布局使用frame,好多方法的使用已经跟不上时代,以学习为主。

新增了登录注册页面和增删兴趣小组的数量,登录和注册网上很多,大家如果想实现可以去搜,兴趣小组的界面见下图:图太大,放上来好丑哦,果断放弃。

还是根据代码片段进行分析吧!
以下是我整个项目的框架:
在这里插入图片描述

兴趣小组初始化界面是三个兴趣小组以及每个兴趣小组的五个学生。页面左右滑动可以到相邻的小组界面,所以我们加入了一个滑动条来指示滑动到当前窗口

#pragma mark -- 初始化滑动的指示View
- (void)initSlideView{
    
    CGFloat width = self.mViewFrame.size.width / 3;
    
    if(self.tabCount <= 6){
        width = self.mViewFrame.size.width / self.tabCount;
    }

    self.slideView = [[UIView alloc] initWithFrame:CGRectMake(0, TOPHEIGHT - 5, width, 5)];
    [self.slideView setBackgroundColor:[UIColor yellowColor]];
    [self.topScrollView addSubview:self.slideView];
}

#pragma mark -- 初始化表格的数据源
- (void)initDataSource{
    self.dataSource = [[NSMutableArray alloc] initWithCapacity:self.tabCount];
    
    for (int i = 1; i <= self.tabCount; i ++) {
        
        NSMutableArray *tempArray  = [[NSMutableArray alloc] initWithCapacity:self.studentcount];
        
        for (int j = 1; j <= self.studentcount ; j++) {
            
            NSString *tempStr = [NSString stringWithFormat:@"第%d个学生",j];
            [tempArray addObject:tempStr];
        }
        
        [self.dataSource addObject:tempArray];
    }
}

我们在底部加入消息栏,进行小组内成员的退改选操作,小组成员的超限是5个成员,若当前小组无人时,再次退选,则弹窗警告:退选识别。同理当超出小组的额度值时,则选择失败。

#pragma mark --初始化消息栏
- (void)initMessageView{
    CGFloat width = self.mViewFrame.size.width;
    
    self.MessageView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_SIZE.height-TOPHEIGHT*5 , width,  SCREEN_SIZE.height - 320)];
    [self.MessageView setBackgroundColor:[UIColor lightGrayColor]];

    self.lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, TOPHEIGHT)];
    self.lable.text = @"消息栏:";
    self.tuiButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.tuiButton.frame = CGRectMake(0, 60, 100, 30);
    [self.tuiButton setTitle:@"退选当前小组" forState:UIControlStateNormal];
    self.tuiButton.layer.masksToBounds = YES;
    self.tuiButton.layer.cornerRadius = 10;
    self.tuiButton.backgroundColor = [UIColor whiteColor];
    [self.tuiButton addTarget:self action:@selector(tui) forControlEvents:UIControlEventTouchUpInside];
    self.choiceButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.choiceButton.frame = CGRectMake(270, 60, 100, 30);
    [self.choiceButton setTitle:@"选择当前小组" forState:UIControlStateNormal];
    self.choiceButton.layer.masksToBounds = YES;
    self.choiceButton.layer.cornerRadius = 10;
    self.choiceButton.backgroundColor = [UIColor whiteColor];
    [self.choiceButton addTarget:self action:@selector(choice) forControlEvents:UIControlEventTouchUpInside];

    [self.MessageView addSubview:self.tuiButton];
    [self.MessageView addSubview:self.choiceButton];
    [self.MessageView addSubview:self.lable];
    [self addSubview:_MessageView];
}

在顶部的左右两侧加入增删小组的按钮,设置小组的数量额度为1-6,超出额度值后增删均不成功。

- (void)minus {
//    [_slideTabBarView removeFromSuperview];
    if (self.tabCount > 1) {
        [_slideTabBarView removeFromSuperview];
        [self initSlideWithCount:--self.tabCount and:self.studentcount];
    }else {
        //lable.text
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"已是最后一个小组" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        }];
        [alertController addAction:action];
        [self presentViewController:alertController animated:YES completion:nil];
    }
    
}


- (void)add {
 //   [self.slideTabBarView removeFromSuperview];
    if (self.tabCount < 6) {
        [self.slideTabBarView removeFromSuperview];
        [self initSlideWithCount:++self.tabCount and:self.studentcount];
    }else {
        //lable.text
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"小组已达上限" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        }];
        [alertController addAction:action];
        [self presentViewController:alertController animated:YES completion:nil];
    }
   
}

整个页面的布局很简洁

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor  = [UIColor whiteColor];
    self.tabCount = 3;
    self.studentcount = 5;
    [self initSlideWithCount:self.tabCount and:self.studentcount];
    //[self initMessageView];
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(140, 14, SCREEN_SIZE.width, 30)];
    [lable setText:@"兴趣小组"];
    lable.font = [UIFont systemFontOfSize:24];
    lable.textColor = [UIColor blackColor];
    [self.view addSubview:lable];
    UIButton *jianButton = [UIButton buttonWithType:UIButtonTypeSystem];
    jianButton.frame = CGRectMake(0, 35, 50, 25);
    [jianButton setTitle:@"减少" forState:UIControlStateNormal];
    jianButton.layer.masksToBounds = YES;
    jianButton.layer.cornerRadius = 10;
    jianButton.backgroundColor = [UIColor whiteColor];
    [jianButton addTarget:self action:@selector(minus) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:jianButton];

    UIButton *addButton = [UIButton buttonWithType:UIButtonTypeSystem];
    addButton.frame = CGRectMake(SCREEN_SIZE.width-50, 35, 50, 25);
    [addButton setTitle:@"增加" forState:UIControlStateNormal];
    addButton.layer.masksToBounds = YES;
    addButton.layer.cornerRadius = 10;
    addButton.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:addButton];
    [addButton addTarget:self action:@selector(add) forControlEvents:UIControlEventTouchUpInside];
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值