[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;
            }
        }
    }
}

iOS-UITabbar自定义的更多相关文章

  1. iOS 如何自定义UISearchBar 中textField的高度

    iOS 如何自定义UISearchBar 中textField的高度 只需设置下边的方法就可以 [_searchBar setSearchFieldBackgroundImage:[UIImage i ...

  2. iOS 隐藏自定义tabbar

    iOS  隐藏自定义tabbar -(void)viewWillAppear:(BOOL)animated { NSArray *array=self.tabBarController.view.su ...

  3. ios 实现自定义状态栏StatusBar 和 导航栏navigationBar 的状态和颜色

    很多app中可以看到不同与导航栏的状态栏的颜色,他妈的真绕嘴. 一.更改状态栏颜色 (StatusBar) 就是比如导航栏是红色的状态栏是绿色的. 要实现这样的效果其实很简单,就是添加一个背景view ...

  4. iOS项目——自定义UITabBar与布局

    在上一篇文章iOS项目——基本框架搭建中,我们详细说明了如何对TabBarItem的图片属性以及文字属性进行一些自定义配置.但是,很多时候,我们需要修改TabBarItem的图片和文字属性之外,还需要 ...

  5. iOS之自定义UITabBar替换系统默认的(添加“+”号按钮)

    自定义UITabBar替换系统默认的,目的是为了在UITabBar中间位置添加一个“+号按钮”,下面我们来聊聊具体的实现. 1.自定义WBTabBar,让其继承自UITabBar,代码如下: // / ...

  6. ios之自定义UINavigationBar

    ios5 自定义导航条问题 在ios5之前的系统中,可以通过定义导航条类别的方式自定义导航条: @implementation UINavigationBar (CustomImage)- (void ...

  7. ios UIWebView自定义Alert风格的弹框

    之前开发过一个App,因为公司之前写好了网页版的内容和安卓版本的App,我进去后老板要求我ios直接用网页的内容,而不需要自己再搭建框架.我一听,偷笑了,这不就是一个UIWebView吗?简单! 但是 ...

  8. 【IOS】自定义可点击的多文本跑马灯YFRollingLabel

    需求 项目中需要用到跑马灯来仅展示一条消息,长度合适则不滚动,过长则循环滚动. 虽然不是我写的,但看了看代码,是在一个UIView里面放入两个UILabel, 在前一个快结束的时候,另一个显示.然而点 ...

  9. iOS - 使用自定义字体-苹方字体

    苹方提供了六个字重,font-family 定义如下:苹方-简 常规体font-family: PingFangSC-Regular, sans-serif;苹方-简 极细体font-family: ...

  10. [IOS]swift自定义uicollectionviewcell

    刚刚接触swift以及ios,不是很理解有的逻辑,导致某些问题.这里分享一下swift自定义uicollectionviewcell 首先我的viewcontroller不是直接继承uicollect ...

随机推荐

  1. 前端面试题-JavaScript

    引用GitHub 上 ltadpoles的前端面试 https://github.com/ltadpoles 目录  1. JavaScript 有哪些数据类型  2. 怎么判断不同的JS数据类型   ...

  2. 入门: 在Windows上搭建Flutter开发环境

    使用镜像 由于在国内访问Flutter有时可能会受到限制,Flutter官方为中国开发者搭建了临时镜像,大家可以将如下环境变量加入到用户环境变量中: export PUB_HOSTED_URL=htt ...

  3. LeetCode 294. Flip Game II

    原题链接在这里:https://leetcode.com/problems/flip-game-ii/ 题目: You are playing the following Flip Game with ...

  4. 十五.DNS子域授权、分离解析、缓存DNS服务器

    1.搭建基本DNS服务器 pc7: 1.1 安装软件包 ]# yum -y install bind-chroot bind bind         //域名服务包 bind-chroot  //提 ...

  5. wangEditor编辑器从word粘贴公式

    图片的复制无非有两种方法,一种是图片直接上传到服务器,另外一种转换成二进制流的base64码目前限chrome浏览器使用首先以um-editor的二进制流保存为例:打开umeditor.js,找到UM ...

  6. CF843D Dynamic Shortest Path spfa+剪枝

    考试的T3,拿暴力+剪枝卡过去了. 没想到 CF 上也能过 ~ code: #include <bits/stdc++.h> #define N 100004 #define LL lon ...

  7. 基于评分的商品top-N推荐系统

    import io # needed because of weird encoding of u.item file import os from surprise import KNNBaseli ...

  8. 爬虫(四):BeautifulSoup库的使用

    一:beautifulsoup简介 beautifulsoup是一个非常强大的工具,爬虫利器. beautifulSoup “美味的汤,绿色的浓汤” 一个灵活又方便的网页解析库,处理高效,支持多种解析 ...

  9. pandas 筛选某一列最大值最小值 sort_values、groupby、max、min

    高效方法: dfs[dfs['delta'].isnull()==False].sort_values(by='delta', ascending=True).groupby('Call_Number ...

  10. x2goserver 连接问题

    The remote proxy closed the connection while negotiating the session. This may be due to the wrong a ...