本文转载至 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

UITabBarItem如何更改高度的更多相关文章

  1. css设置select高度(IE,FF,Chrome)[转]

    大家都知道select是无法设置高度和边框颜色等等的在ie67下面,其他的都是可以的,所以有时候为了在所有的浏览器下显示都一致,就使用了 js的模拟,这个是大家经常碰到的,js不光要模拟外观还有模拟事 ...

  2. html5 getComputedStyle + resize 实现动态宽高度等比响应式页面设计

    序:通常我们只能控制div的宽度 而不能控制高度,在响应式页面里 如果要这个div是正方形那么必须的用媒体查询在不同的分辨率下写死宽高度 今天突发奇想研究了个 用百分比来动态控制div的高度让其与宽度 ...

  3. iOS - UITextView放在自定义cell里面-自适应高度

    textView放在自定义cell里面-自适应高度 1,textView有个属性 scrollEnabled  要设置为NO; 2,设置tableview的时候  添加这两行代码: self.tabl ...

  4. iOS:小技巧(不断更新)

    记录下一些不常用技巧,以防忘记,复制用. 1.获取当前的View在Window的frame: UIWindow * window=[[[UIApplication sharedApplication] ...

  5. iOS:小技巧(19-02-12更)

    记录下一些不常用技巧,以防忘记,复制用. 1.UIImageView 和UILabel 等一些控件,需要加这句才能成功setCorn _myLabel.layer.masksToBounds = YE ...

  6. RecyclerView使用大全

    RecylerView介绍 RecylerView是support-v7包中的新组件,是一个强大的滑动组件,与经典的ListView相比,同样拥有item回收复用的功能,这一点从它的名字recyler ...

  7. {POJ}{3897}{Maze Stretching}{二分答案+BFS}

    题意:给定迷宫,可以更改高度比,问如何使最短路等于输入数据. 思路:由于是单调的,可以用二分答案,然后BFS验证.这里用优先队列,每次压入也要进行检查(dis大小)防止数据过多,A*也可以.好久不写图 ...

  8. UI学习笔记---第十一天UITableView表视图高级-自定义cell

    自定义cell,多类型cell混合使用,cell自适应高度 自定义cell就是创建一个UITableViewCell的子类 把cell上的空间创建都封装在子类中,简化viewController中的代 ...

  9. UITabelView 高级(自定义Cell)

    自定义一个Cell 当我们要显示复杂数据的时候,例如要做一个扣扣聊天界面,或是新闻列表,系统的行已经不能满足我们的要求,这个时候我们可以通过自定义这个行,让他显示更多复杂结构的样式. 自定义cell就 ...

随机推荐

  1. windowsclient开发--怎样測量一个字符串显示的物理长度

    首先须要说明的是,我所说的字符串的长度,不是string的length,也不是string的size.我指的是显示的长度.即物理长度. 缘由: 之所以要提到这个.是由于遇到了一些问题. 再使用duil ...

  2. json 生成 json字符串

    生成json格式的字符串. 需要相关包 json-lib-2.3-jdk15.jar morph-1.1.1.jar morph-sandbox-1.1.1.jar ezmorph-1.0.6.jar ...

  3. 关于同一线程两次调用EnterCriticalSection的测试

    #include "stdafx.h" #include <iostream> using namespace std; #include <windows.h& ...

  4. phpexcel 读取日期的问题?

    phpexcel 读取excel数字时,显示为一串数字(时间都是类似于这样的数字:41890.620138889),如何将数字转换为对应的日期来显示呢?特别是例如星期一这种的时间. 可以用phpexc ...

  5. EMQ学习笔记---Clean Session和Retained Message

    MQTT会话(Clean Session)MQTT客户端向服务器发起CONNECT请求时,可以通过’Clean Session’标志设置会话.‘Clean Session’设置为0,表示创建一个持久会 ...

  6. swipeRefreshLayout与webview滑动冲突

    遇到这么个bug,webview使用swipeRefreshLayout时,下拉时事件不会被webview捕获,而是执行swipeRefreshLayout的刷新,网上一大堆一大堆的解决办法,都是什么 ...

  7. Spring学习笔记(四)-- Spring事务全面分析

    通过本系列的文章对Spring的介绍,我们对Spring的使用和两个核心功能IOC.AOP已经有了初步的了解,结合我个人工作的情况,因为项目是金融系 统.那对事务的控制是不可缺少的.而且是很严格的控制 ...

  8. macbook使用“终端”远程登录linux主机

    登录mac系统后,依次打开顶部菜单,“前往” -> “应用程序” -> “实用工具” -> “终端”,如下图:   在打开的终端页面,输入如下代码: ssh user@hostnam ...

  9. [转]PHP运行出现Notice : Use of undefined constant 的完美解决方案

    Notice: Use of undefined constant title - assumed 'title' in F:\wamp\www\load_myweb.php on line 22No ...

  10. C#使用技巧之调用JS脚本(转)

    .创建个Winform项目. .在From1上增加一个文本框一个按钮. .在解决方案中创建一个test.js文件. test.js代码如下: function sayHello(str) { retu ...