zoukankan      html  css  js  c++  java
  • UITabBarItem如何更改高度

       

    本文转载至 http://www.cocoachina.com/bbs/read.php?tid=255361 

     

     

    我目前有个UITabBar,改了它的高度。但是我切换页签后,这个UITabBar样式又变掉了。我感觉是UITabBarItem的高度把整个页签高度撑开了。

     

    不知道如何修改UITabBarItem,最好是能去掉文字占用的空间,因为我只要图片,不要文字的。能不能把文字移除。

     

     

     

    回复

    引用

    举报顶端

     

    major李小木

     

     

    级别: 新手上路

     

     

    状态: 未签到 - [3天]

    UID: 292674

    精华: 0 

    发帖: 25

    可可豆: 108 CB

    威望: 100 点

    在线时间: 300(时)

    注册时间: 2014-02-16

    最后登录: 2015-04-01

     

    沙发 :

    发表于: 2014-04-11 09:58

       发自: Web Page

    只看该作者   小 中 大

     

     

     

     

    如果不是系统样式的tabbar,建议你还是自定义一个tabbar

     

     

     

    给你一个自定义tabbar的demo,希望可以帮到你

     

     

     

    #import "MainTabBarController.h"

     

    #import "HomePageViewController.h"

     

    #import "ScanningViewController.h"

     

    #import "NearbyViewController.h"

     

    #import "RemindViewController.h"

     

     

     

    #import "DeviceManager.h"

     

     

     

     

     

    @interface MainTabBarController ()

     

    {

     

        UIView * _tabBarView;

     

    }

     

    @end

     

     

     

    @implementation MainTabBarController

     

     

     

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

     

    {

     

        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

     

        if (self) {

     

     

     

        }

     

        return self;

     

    }

     

     

     

    - (void)viewDidLoad

     

    {

     

        [super viewDidLoad];

     

        

     

        [self creatCustomTabBarView];

     

    [self creatControllers];

     

     

     

    }

     

     

     

    #define NormalImages [NSArray arrayWithObjects:@"底部首页按钮",@"底部扫描按钮",@"底部附近按钮",@"底部提醒按钮", nil]

     

    #define SelectedImages [NSArray arrayWithObjects:@"底部首页按钮高亮",@"底部扫描按钮高亮",@"底部附近按钮高亮",@"底部提醒按钮高亮", nil]

     

    -(void)creatCustomTabBarView{

     

        self.tabBar.hidden = YES;

     

        

     

        _tabBarView = [[UIView alloc] initWithFrame:CGRectMake(0, [DeviceManager currentDeviceScreenHeight] - 44, 320, 44)];

     

        for (int i = 0; i< 4; i++) {

     

            UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];

     

            if (i == 0) {

     

                [button setBackgroundImage:[UIImage imageNamed:[SelectedImages objectAtIndex:i]] forState:UIControlStateNormal];

     

            }else{

     

                [button setBackgroundImage:[UIImage imageNamed:[NormalImages objectAtIndex:i]] forState:UIControlStateNormal];

     

            }

     

            [button setFrame:CGRectMake(0+80*i, 0, 80, 44)];

     

            button.tag = 100 + i;

     

            [button addTarget:self action:@selector(clickedButton:) forControlEvents:UIControlEventTouchDown];

     

            [_tabBarView addSubview:button];

     

        }

     

        [self.view addSubview:_tabBarView];

     

    }

     

     

     

     

     

    -(void)creatControllers{

     

        HomePageViewController * hpVC = [[HomePageViewController alloc] init];

     

        ScanningViewController * sVC = [[ScanningViewController alloc] init];

     

        NearbyViewController * nVC = [[NearbyViewController alloc] init];

     

        RemindViewController * rVC = [[RemindViewController alloc] init];

     

        NSArray * viewControllers = [NSArray arrayWithObjects:hpVC,sVC,nVC,rVC, nil];

     

        NSMutableArray * controllers = [[NSMutableArray alloc] init];

     

        for (int i = 0; i< 4; i++) {

     

            UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:[viewControllers objectAtIndex:i]];

     

            [controllers addObject:nav];

     

        }

     

        self.viewControllers = controllers;

     

    }

     

     

     

     

     

     

     

    -(void)clickedButton:(UIButton *)button{

     

        for (int i = 0; i< 4; i++) {

     

            UIButton * btn = (UIButton *)[_tabBarView viewWithTag:(100 + i)];

     

            if (button.tag%100 == i) {

     

                [btn setBackgroundImage:[UIImage imageNamed:[SelectedImages objectAtIndex:i]] forState:UIControlStateNormal];

     

                self.selectedIndex = i;

     

            }else{

     

                [btn setBackgroundImage:[UIImage imageNamed:[NormalImages objectAtIndex:i]] forState:UIControlStateNormal];

     

            }

     

        }

     

    }

     

     

     

     

     

     

     

    - (void)didReceiveMemoryWarning

     

    {

     

        [super didReceiveMemoryWarning];

     

        // Dispose of any resources that can be recreated.

     

    @end

  • 相关阅读:
    HDU 4814 Golden Radio Base 模拟
    Java提高篇(三二)-----List总结
    让你提前认识软件开发(28):数据库存储过程中的重要表信息的保存及相关建议
    BBSXP最新漏洞 简单注入检測 万能password
    CodeForce 356A Knight Tournament(set应用)
    POJ--3268--Silver Cow Party【SPFA+邻接表】
    strip 命令的使用方法
    MySQL创建用户权限结果Trigger失败
    Cocos2d-x3.0下一个 Lua与C++打电话给对方
    sharepoint 2013 userprofile 用户信息
  • 原文地址:https://www.cnblogs.com/Camier-myNiuer/p/4402332.html
Copyright © 2011-2022 走看看