- (void)createTopBtn{
? ? NSMutableArray *TopArr = [NSMutableArray arrayWithObjects:@"移動",@"傳媒",@"網(wǎng)工",@"軟工",@"游戲",@"+", nil];
? ? //創(chuàng)建循環(huán)按鈕
? ? for (int i = 0; i < TopArr.count; i++)
? ? {
? ? ? ? UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
? ? ? ? //設(shè)置按鈕顏色
? ? ? ? if (i == 0)
? ? ? ? {
? ? ? ? ? ? btn.backgroundColor = [UIColor orangeColor];
? ? ? ? }
? ? ? ? else if (i == 5)
? ? ? ? {
? ? ? ? ? ? [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
? ? ? ? ? ? [btn setTitleColor:[UIColor yellowColor] forState:UIControlStateSelected];
? ? ? ? ? ? btn.backgroundColor = [UIColor lightGrayColor];
? ? ? ? ? ? btn.titleLabel.font = [UIFont systemFontOfSize:26];
?? [btn addTarget:self action:@selector(addClick:) forControlEvents:UIControlEventTouchUpInside];
? ? ? ? ? ? btn.selected = NO;
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? btn.backgroundColor = [UIColor orangeColor];
? ? ? ? }
? ? ? ? btn.frame = CGRectMake(i * 70, 64, 70, 50);
? ? ? ? btn.tag = 100+i;
? ? ? ? [btn setTitle:[TopArr objectAtIndex:i] forState:UIControlStateNormal];
? ? ? ? btn.backgroundColor = [UIColor whiteColor];
? ? ? ? [btn addTarget:self action:@selector(MoveClick:) forControlEvents:UIControlEventTouchUpInside];
? ? ? ? [self.view addSubview:btn];
? ? }
}
- (void)MoveClick:(UIButton *)btn
{
? ? for (int i = 0; i<5; i++)
? ? {
? ? ? ? //根據(jù)tag獲取按鈕
? ? ? ? UIButton *btn1 = [self.view viewWithTag:100 + i];
? ? ? ? if (btn.tag == btn1.tag)
? ? ? ? {
? ? ? ? ? ? btn1.backgroundColor = [UIColor orangeColor];
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? btn1.backgroundColor = [UIColor grayColor];
? ? ? ? }
? ? }
}
//創(chuàng)建滾動視圖
- (void)createScollView
{
? ? //創(chuàng)建滾動視圖 設(shè)置位置
? ? UIScrollView *bigScorllView? = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64+ 50, self.view.frame.size.width, self.view.frame.size.height - 64 - 50)];
? ? //設(shè)置偏移量
? ? bigScorllView.contentSize = CGSizeMake(self.view.frame.size.width *5, 0);
? ? //設(shè)置代理協(xié)議
? ? bigScorllView.delegate = self;
? ? bigScorllView.pagingEnabled = YES;
? ? //設(shè)置tag值
? ? bigScorllView.tag = 50;
? ? bigScorllView.backgroundColor = [UIColor yellowColor];
? ? [bigScorllView setContentOffset:CGPointMake(self.view.frame.size.width, 0)];
? ? [self.view addSubview:bigScorllView];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
? ? if (scrollView.tag == 50)
? ? {
? ? ? ? //根據(jù)當(dāng)前視圖的偏移量設(shè)置當(dāng)前的按鈕位置
? ? ? ? for (int i=0; i<5; i++)
? ? ? ? {
? ? ? ? ? ? //根據(jù)tag獲取
? ? ? ? ? ? UIButton *btn1 = [self.view viewWithTag:100+i];
? ? ? ? ? ? if (scrollView.contentOffset.x/self.view.frame.size.width == (btn1.tag - 100))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? btn1.backgroundColor = [UIColor orangeColor];
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? btn1.backgroundColor = [UIColor grayColor];
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
- (void)addClick:(UIButton *)sender
{
? ? if (sender.tag == 105) {
? ? ? ? if (sender.selected == YES) {
? ? ? ? ? ? sender.selected = NO;
? ? ? ? ? ? view1.hidden = YES;
? ? ? ? }
? ? ? ? else{
? ? ? ? ? ? sender.selected = YES;
? ? ? ? ? ? view1.hidden = NO;
? ? ? ? }
? ? }
}
//數(shù)據(jù)源方法
//默認(rèn)1組
//行數(shù)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
? ? return 3;
}
//設(shè)置單元格 cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
? ? //根據(jù)可重用標(biāo)識符查找cell
? ? UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];
? ? //設(shè)置cell內(nèi)容
? ? NSArray *arr = @[@"確定添加",@"確定刪除",@"關(guān)閉"];
? ? cell.textLabel.text = arr[indexPath.row];
? ? cell.backgroundColor = [UIColor greenColor];
? ? return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? if (indexPath.row == 2)
? ? {
? ? ? ? view1.hidden = YES;
? ? }
? ? else if (indexPath.row == 0)
? ? {
? ? ? ? UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"確認(rèn)添加" message:@"操作已成功" preferredStyle:UIAlertControllerStyleAlert];
? ? ? ? UIAlertAction *action = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
? ? ? ? }];
? ? ? ? ? ? [alert addAction:action];
? ? ? ? ? ? [self.navigationController presentViewController:alert animated:YES completion:^{
? ? ? ? ? ? }];
? ? }
? ? else
? ? {
? ? ? ? UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"確認(rèn)刪除" message:@"操作已成功" preferredStyle:UIAlertControllerStyleAlert];
? ? ? ? UIAlertAction *action = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
? ? ? ? }];
? ? ? ? [alert addAction:action];
? ? ? ? [self.navigationController presentViewController:alert animated:YES completion:^{
? ? ? ? }];
? ? }
}