qq_33809905
qq_33809905
采纳率75%
2016-01-27 09:48 阅读 3.2k
已采纳

ios的tabbar问题求详细解答,这个tabbar下面的图标突出一块怎么做的。谢谢各位大神。

图片

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

5条回答 默认 最新

  • 已采纳
    Margaret_MO Mo_Xiao_Yan 2016-03-03 06:21

    自己自定义一个标签视图控制器吧:
    自定义一个类继承自UITabBarController;
    然后在该类的.m文件中自己写button和其点击事件间的切换

    #import "MyTabBarController.h"

    #define WIDTH (myView.frame.size.width / 4)
    #define HEIGHT (myView.frame.size.height)

    @interface MyTabBarController ()

    //之前选中的按钮
    @property(nonatomic, retain) UIButton *selectedBtn;

    @end

    @implementation MyTabBarController

    • (void)viewDidLoad {
      [super viewDidLoad];
      //删除现有的tabBar
      CGRect rect = self.tabBar.frame;
      [self.tabBar removeFromSuperview];

      //添加自己的视图
      UIView *myView = [[BaseView alloc] init];
      myView.backgroundColor = [UIColor whiteColor];
      myView.frame = rect;
      [self.view addSubview:myView];

      //主页发现按钮
      UIButton *findBtn = [UIButton buttonWithType:UIButtonTypeCustom];
      [findBtn setImage:[UIImage imageNamed:@"icon_home_n"] forState:UIControlStateNormal];
      [findBtn setImage:[UIImage imageNamed:@"icon_home_h"] forState:UIControlStateSelected];
      findBtn.tag = 1;
      findBtn.frame = CGRectMake(0, -20, WIDTH, HEIGHT); //y设成负值,高再设高一点就好了!!!
      //默认选中是发现按钮
      findBtn.selected = YES;
      [findBtn setTintColor:[UIColor colorWithRed:0.886 green:0.365 blue:0.247 alpha:1.000]];
      self.selectedBtn = findBtn;
      [myView addSubview:findBtn];

      UILabel *findLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH/2 -10, HEIGHT - 20, WIDTH, 20)];
      findLabel.text = @"发现";
      findLabel.textColor = [UIColor colorWithRed:0.804 green:0.325 blue:0.227 alpha:1.000];
      findLabel.font = [UIFont systemFontOfSize:10];
      findLabel.tag = 101;
      [myView addSubview:findLabel];
      [findLabel release];

      //搜索页
      UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
      [searchBtn setImage:[UIImage imageNamed:@"icon_search_n"] forState:UIControlStateNormal];
      [searchBtn setImage:[UIImage imageNamed:@"icon_search_h"] forState:UIControlStateSelected];
      searchBtn.tag = 2;
      searchBtn.frame = CGRectMake(WIDTH, -20, WIDTH, HEIGHT);
      [myView addSubview:searchBtn];

      UILabel *searchLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH + WIDTH/2 -10, HEIGHT - 20, WIDTH, 20)];
      searchLabel.text = @"搜索";
      searchLabel.textColor = [UIColor grayColor];
      searchLabel.font = [UIFont systemFontOfSize:10];
      searchLabel.tag = 102;
      [myView addSubview:searchLabel];
      [searchLabel release];

      //收藏页
      UIButton *costBtn = [UIButton buttonWithType:UIButtonTypeCustom];
      [costBtn setImage:[UIImage imageNamed:@"iconfont-like"] forState:UIControlStateNormal];
      [costBtn setImage:[UIImage imageNamed:@"iconfont-like-selected"] forState:UIControlStateSelected];
      costBtn.tag = 3;
      costBtn.frame = CGRectMake(2 * WIDTH, -20, WIDTH, HEIGHT);
      [myView addSubview:costBtn];

      UILabel *collectLabel = [[UILabel alloc] initWithFrame:CGRectMake(2 * WIDTH + WIDTH/2 -10, HEIGHT - 20, WIDTH, 20)];
      collectLabel.text = @"收藏";
      collectLabel.textColor = [UIColor grayColor];
      collectLabel.font = [UIFont systemFontOfSize:10];
      collectLabel.tag = 103;
      [myView addSubview:collectLabel];
      [collectLabel release];

      //设置页
      UIButton *setUpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
      [setUpBtn setImage:[UIImage imageNamed:@"icon_setting_n"] forState:UIControlStateNormal];
      [setUpBtn setImage:[UIImage imageNamed:@"icon_setting_h"] forState:UIControlStateSelected];
      setUpBtn.tag = 4;
      setUpBtn.frame = CGRectMake(3 * WIDTH, -20, WIDTH, HEIGHT);
      [myView addSubview:setUpBtn];

      UILabel *setUpLabel = [[UILabel alloc] initWithFrame:CGRectMake(3 * WIDTH + WIDTH/2 -10, HEIGHT - 20, WIDTH, 20)];
      setUpLabel.text = @"设置";
      setUpLabel.textColor = [UIColor grayColor];
      setUpLabel.font = [UIFont systemFontOfSize:10];
      setUpLabel.tag = 104;
      [myView addSubview:setUpLabel];
      [setUpLabel release];

      for (int i = 1; i <4; i++) {
      UIButton *btn = [self.view viewWithTag:i];
      [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
      }
      }

    #pragma mark -- 自定义tabBar按钮的点击事件
    -(void)clickBtn:(UIButton *)sender {
    //设置上一个按钮
    self.selectedBtn.selected = NO;
    UILabel *titleFormer = [self.view viewWithTag:self.selectedBtn.tag + 100];
    titleFormer.textColor = [UIColor grayColor];

    //设置选中状态
    sender.selected = YES;
    self.selectedBtn = sender;
    UILabel *titleNow = [self.view viewWithTag:self.selectedBtn.tag + 100];
    titleNow.textColor = [UIColor colorWithRed:0.804 green:0.325 blue:0.227 alpha:1.000];
    
    //跳转相应的视图控制器
    self.selectedIndex = sender.tag - 1;
    

    }

    点赞 评论 复制链接分享
  • oyljerry oyljerry 2016-01-27 10:13

    自己放ImageView等,把图片贴过去

    点赞 评论 复制链接分享
  • dd90702 青欢 2016-01-29 08:45

    点击的时候将图片的frame变大不就行了

    点赞 评论 复制链接分享
  • TonyShanM TonyShanM 2016-01-29 14:37

    自己在 tabbar 上添加一个 比 tabbar 稍高一点的view, 在 view 上添加四个按钮,把每个按钮的图片设置成图中需要的小猴子图片,点击按钮的时候去通知控制器改变 tabbar

    点赞 评论 复制链接分享
  • Bonway_Huang Bonway_Huang 2018-11-15 02:10

    可以去 https://github.com/Bonway/BBGestureBack 看一下就解决了

    点赞 评论 复制链接分享

相关推荐