滾動 (隱藏檢視)
阿新 • • 發佈:2018-12-17
#import “ViewController.h” #import “YdViewController.h” #import “CmViewController.h” #import “RgViewController.h” #import “WgViewController.h” #import “YjsViewController.h” #import “JzViewController.h” #import “WzViewController.h” #import “XLSlideSwitch.h” @interface ViewController (){ UIButton *Btn; UIView *SomeView; } @property (nonatomic , strong)XLSlideSwitch *ScrollView; @end @implementation ViewController (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @“八維教育”; self.view.backgroundColor =[UIColor blueColor]; NSArray *TitlesArr = @[@“移動通訊” , @“傳媒” , @“軟工” , @“網工” , @“雲端計算” , @“建築”,@“網工”]; NSArray *ControllersArr = @[@“YdViewController” , @“CmViewController” , @“RgViewController” , @“WgViewController” , @“YjsViewController” , @“JzViewController”,@“WzViewController”]; NSMutableArray *ViewControllers = [[NSMutableArray alloc] init]; for (int i = 0 ; i < TitlesArr.count; i ++) { //字串建立控制器 UIViewController *VC = [[NSClassFromString(ControllersArr[i])alloc] init]; [ViewControllers addObject:VC]; } //滾動檢視 _ScrollView = [[XLSlideSwitch alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64) Titles:TitlesArr viewControllers:ViewControllers]; _ScrollView.delegate = self; _ScrollView.itemNormalColor = [UIColor darkGrayColor]; _ScrollView.itemSelectedColor = self.navigationController.navigationBar.tintColor; _ScrollView.customTitleSpacing = 30; _ScrollView.moreButton = [self moreButton]; [_ScrollView showInViewController:self]; //w點選隱藏 或 不隱藏View SomeView = [[UIView alloc]initWithFrame:CGRectMake(260, 105, 154, 200)]; SomeView.backgroundColor = [UIColor orangeColor]; SomeView.hidden=YES; NSArray *arr = @[@“確認新增”,@“刪除新增”,@“關閉”]; for (int i = 0; i<arr.count; i++) { UIButton btn1 = [[UIButton alloc]initWithFrame:CGRectMake(2, 5+ i60, 150, 60)]; [btn1 setTitle:arr[i] forState:UIControlStateNormal]; [btn1 addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchUpInside]; btn1.tag = 100+i; btn1.backgroundColor = [UIColor redColor]; [SomeView addSubview:btn1]; } [self.view addSubview:SomeView]; } (UIButton *)moreButton{ Btn = [[UIButton alloc] init]; // [button setImage:[UIImage imageNamed:@“channelAdd”] forState:UIControlStateNormal]; [Btn setTitle:@“➕” forState:UIControlStateNormal]; [Btn setImageEdgeInsets:UIEdgeInsetsMake(8, 8, 8, 8)]; [Btn addTarget:self action:@selector(BtnTouchUpInside) forControlEvents:UIControlEventTouchUpInside]; return Btn; } (void)BtnTouchUpInside{ NSLog(@“點選了新增按鈕”); if (Btn.selected == YES) { // SomeView.hidden = YES; Btn.selected = NO; SomeView.hidden = YES; }else{ Btn.selected = YES; SomeView.hidden = NO; } } (void)btn:(UIButton *)button{ if (button.tag == 100) { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@“確認新增” message:@“操作已完成” delegate:self cancelButtonTitle:@“確認” otherButtonTitles:nil, nil]; [alert show]; }else if (button.tag == 101){ NSLog(@“222”); }else{ NSLog(@“333”); } } @end