zoukankan      html  css  js  c++  java
  • iOS-UITabbar自定义

    [self createCustomTabBar];

    -(void)createCustomTabBar{
        //创建一个UIImageView,作为底图
        UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0,[UIScreen mainScreen].bounds.size.height-49, 320, 49)];
        bgView.image = [UIImage imageNamed:@"tabbg.png"];
        bgView.tag = 999;
        //开启imageview的交互属性
        bgView.userInteractionEnabled = YES;
        [self.view addSubview:bgView];
       
        
        //创建button实例  模拟tabBarItem
        //每个button的间
        NSArray *array=[NSArray arrayWithObjects:@"IconSettings",@"IconProfile",@"IconHome",@"IconEmpty",@"IconCalendar",@"btn_bottom1_on.png",@"btn_bottom2_on.png",@"btn_bottom3_on.png",@"btn_bottom4_on.png",@"btn_bottom5_on.png", nil];
        for (int i = 0; i<(array.count)/2; i++) {
            NSString *imageName = [array objectAtIndex:i];
            NSString *selectedImage = [array objectAtIndex:i+5];
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn setFrame:CGRectMake(0+64*i, 0, 64, 49)];
            //设置button处于常规状态下的背景图片
            [btn setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
            //设置button处于选中状态下得背景图片
            [btn setBackgroundImage:[UIImage imageNamed:selectedImage] forState:UIControlStateSelected];
            [btn addTarget:self
                    action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
            btn.tag = i;
            
            if (i==0) {
                btn.selected = YES;
            }
            
            [bgView addSubview:btn];
        }
    }
    -(void)btnClicked:(UIButton *)btn
    {
        //点击不同的按钮,切换不同的视图控制器
        self.selectedIndex = btn.tag;
        //切换不同btn的显示状态
        UIImageView *bgView = (UIImageView *)[self.view viewWithTag:999];
        for (UIView *subView in bgView.subviews) {
            if ([subView isKindOfClass:[UIButton class]]) {
                UIButton *btn1 = (UIButton *)subView;
                if (btn1.tag == btn.tag) {
                    btn1.selected = YES;
                }else{
                    btn1.selected = NO;
                }
            }
        }
    }

  • 相关阅读:
    poj 2676 Suduku (dfs)
    poj 1562 Oil Deposits (dfs)
    poj 2907 Collecting Beepers (dfs)
    poj 1655 Balancing Act (树形dfs)
    poj 3411 Paid Roads (dfs)
    hdu 2896 病毒侵袭 (AC)
    hdu 3065 病毒侵袭持续中 (AC)
    poj 2251 Dungeon Master (bfs)
    java中debug使用
    Swing入门级小项目总结
  • 原文地址:https://www.cnblogs.com/linxiu-0925/p/5422113.html
Copyright © 2011-2022 走看看