当前位置: 首页 > 工具软件 > PopView > 使用案例 >

类似POPView菜单

费凯康
2023-12-01
-(void)btnClick:(UIButton *)button{
    if (self.btnStatus == YES) {
        [self.btn setImage:self.btnImageOff forState:UIControlStateNormal];
        [self addFenleiController];
        _fenleiController.view.hidden=NO;
    }
    else{
        [self.btn setImage:self.btnImageOn forState:UIControlStateNormal];
        
        _fenleiController.view.hidden = YES;
    }
    self.btnStatus = !self.btnStatus;
 
}
-(void)addFenleiController{
    _fenleiController =[[FenleiViewController alloc]init];
    _fenleiController.view.backgroundColor=[UIColor whiteColor];
    _fenleiController.view.frame =CGRectMake(0, 105, self.view.frame.size.width, 300);
    [_fenleiController willMoveToParentViewController:self];
    [self addChildViewController:_fenleiController];
    [self.view addSubview:_fenleiController.view];
    [_fenleiController didMoveToParentViewController:self];
    float length =(_fenleiController.view.frame.size.width-10)/4;
    NSArray *arr =@[@"巧手搭配",@"趣致创意",@"收纳控",@"食色",@"绿植",@"萌宠",@"生活杂事",@"DIY",@"相夫教子",@"别人的生活",@"洗刷刷",@"晒物",@"求助&经验"];
    for (int i=0; i<4; i++) {
        for (int j=0;j<4 ; j++) {
            UIButton *button=[UIButton buttonWithType:UIButtonTypeSystem];
            button.frame=CGRectMake(j*length+10, i*50+30, length-10, 30);
            button.backgroundColor =[UIColor groupTableViewBackgroundColor];
            [button setTitle:arr[i*4+j] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(buttonClick1:) forControlEvents:UIControlEventTouchUpInside];
            button.tag =101+(i*4+j+2);
            [_fenleiController.view addSubview:button];
            if (j==0&&i==3) {
                
                return;
            }
        }
    }
}

 类似资料: