本文介绍: 继上次用Objective_C类的方式实现兴趣小组,以iOS界面方法再次呈现一次。作为初学者,方法选择实现简单布局使用frame,好多方法使用已经跟不上时代,以学习为主。新增登录注册页面增删兴趣小组的数量,登录注册网上很多大家如果想实现可以去搜,兴趣小组界面下图:图太大,放上来好丑哦,果断放弃。还是根据代码片段进行分析吧!以下是我整个项目框架兴趣小组初始化界面是三个兴趣小组以及每个兴趣小组的五个学生页面左右滑动可以相邻小组界面,所以我们加入一个滑动条来指示滑动

继上次用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];
}

原文地址:https://blog.csdn.net/YUANdeboke/article/details/122565835

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_44652.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注