ios中 怎么改变uiimage 在获取tabbarcontrollerr中的位置

5136人阅读
今天用到了关于&,看到设计图中的那些效果和系统默认的不一样 所以赶紧上网找些资料去
发现关于它的自定义不少 可是好用的不是很多 大部分都是一样的 并且我用了之后效果不是很明显
但是经过看别人的 总算是组合出来了点结果
首先是修改背景
self.tabBarController = [[ alloc] init];
//定义一个view 里面是一个背景图片
UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 49)];
v.backgroundColor& = [UIColor clearColor];
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@&new-nav-bg.png&]];
img.frame = CGRectMake(0,0, 320,49);
img.contentMode = UIViewContentModeScaleToF
[v addSubview:img];
//这句话是重点 网上都是把数字1 写成了 0 &但是我写0 的时候不能显示效果 1就可以
[self.tabBarController.tabBar insertSubview:v atIndex:1];
其实直接用一幅图片也行的
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@&new-nav-bg.png&]];
img.frame = CGRectMake(0,0, 320,49);
img.contentMode = UIViewContentModeScaleToF
[self.tabBarController.tabBar insertSubview:img atIndex:1];
这样就完成了 效果如下:
其实每个图片都是黑色的 系统默认会加上一些效果 譬如选中 或者没有被选中的时候 如果使用
[con2.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@&tab3.png&] withFinishedUnselectedImage:[UIImage imageNamed:@&tab2.png&]];
con2是tab2 对应的视图控制器 这样自定义选中和未选中的图片之后就完全自己控制了效果如下 并且图片大小不会改变
这张是不会影响尺寸的
还有就是有时候需要进行对tabar的暂时的隐藏或者显示 如果使用 self.tabBarController.tabBar.hidden = YES; 可能是隐藏了 但是tab bar 的位置并没有被占去 而是显示黑色的一条 最后我找到了一个解决的方法
aboutViewCon.hidesBottomBarWhenPushed = YES;//跳入该页面的时候隐藏掉tabbar
[self.navigationController pushViewController:aboutViewCon animated:NO];
aboutViewCon.hidesBottomBarWhenPushed = NO;//跳进去后该页面的时显示tabbar
这样就完美解决了问题
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:473682次
积分:5097
积分:5097
排名:第2404名
原创:12篇
转载:140篇
评论:94条
(2)(2)(4)(4)(9)(5)(3)(1)(12)(6)(104)IOS中UITabBar的常用设置 - 手机系统 - 编程入门网
IOS中UITabBar的常用设置
UITabBar十分常用,它能实现多个页面的快速切换,而且看起来简单实用。
假设我这有多个 已经初始化好的viewController,然后需要将它们加入到TabBarController中,并把其设置为根视图
NSArray *views = [[NSArray alloc] initWithObjects:test, time, test1, test2, test3,
test4, nil];
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers =
self.window.rootViewController =
设置好以后看一下TabBar的效果图
这里的每个View的Item主要有这么几个属性,标题title,图片image,以及time右上的圆圈图 标,显示的是badgeValue。可以在覆写view的初始化方法的时候设置它的tabBarItem属性。
(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.tabBarItem.title = @&time&;
self.tabBarItem.image = [UIImage imageNamed:@&time.png&];
self.tabBarItem.badgeValue = [NSString stringWithFormat:@&%d&, 3];
再看一下效果图的最右边,它是More,这是因为TabBar默认最多显示5个Item,多余的会自动 加到More中去,点击More之后会弹出一个NavigationBar,上面有一个Edit按钮收藏,7.4k 浏览
问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
如题,iOS 7怎样实现内容view的高度调整?沿用iOS 6的方法是不行的
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
请问你是想自定义 tabbar 的高度还是想调整 content view 的高度?
你可以使用下面的方法来打印出 UITabBarController 的 View 的子视图信息来查看视图层级的布局:
- (void)viewDidAppear:(BOOL)animated
[super viewDidAppear:animated];
[self printViewHierarchy:self.tabBarController.view];
- (void)printViewHierarchy:(UIView *)superView
static uint level = 0;
for(uint i = 0; i & i++){
printf("\t");
const char *className = NSStringFromClass([superView class]).UTF8S
const char *frame = NSStringFromCGRect(superView.frame).UTF8S
printf("%s:%s\n", className, frame);
for(UIView *view in superView.subviews){
[self printViewHierarchy:view];
UILayoutContainerView:{{0, 0}, {320, 480}}
UITransitionView:{{0, 0}, {320, 480}}
UIViewControllerWrapperView:{{0, 0}, {320, 480}}
UIView:{{0, 0}, {320, 480}}
UITabBar:{{0, 431}, {320, 49}}
_UITabBarBackgroundView:{{0, 0}, {320, 49}}
_UIBackdropView:{{0, 0}, {320, 49}}
_UIBackdropEffectView:{{0, 0}, {320, 49}}
UIView:{{0, 0}, {320, 49}}
UITabBarButton:{{2, 1}, {156, 48}}
UITabBarSwappableImageView:{{54, 2}, {48, 32}}
UITabBarButtonLabel:{{68, 35}, {21, 12}}
UITabBarButton:{{162, 1}, {156, 48}}
UITabBarSwappableImageView:{{54, 2}, {48, 32}}
UITabBarButtonLabel:{{60, 35}, {36, 12}}
UIImageView:{{0, -0.5}, {320, 0.5}}
同步到新浪微博
不要错过该问题的后续解决方案
如果你没找到答案,记得登录关注哦,大家会尽全力帮你解决的 ^___^
分享到微博?
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
举报理由:
推广(招聘、广告、SEO 等)方面的内容
带有人身攻击、辱骂、仇恨等违反条款的内容
与已有问题重复(请编辑该提问指向已有相同问题)
内容质量差,或不适合在本网站出现
答非所问,不符合答题要求
其他原因(请补充说明)
补充说明:

我要回帖

更多关于 获取tabbarcontroller 的文章

 

随机推荐