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

posted @ 2015-04-08 14:30  天牛  阅读(403)  评论(0编辑  收藏  举报