带有自动调整大小的 UITabBar
Posted
技术标签:
【中文标题】带有自动调整大小的 UITabBar【英文标题】:UITabBar with autoresize 【发布时间】:2013-01-23 17:19:35 【问题描述】:我在 iPhone 和 iPad 应用程序中使用 UITabBar
,但是当我进入横向模式时,自动调整大小在 iPad 上不起作用(它在 iPhone 上工作正常)。
tabBarController =[[UITabBarController alloc]init];
tabBarController.delegate=self;
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController1,navController2, navController3,navController4,navController5,nil];
tabBarController.selectedViewController = navController1;
imgTab = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,768.0,51)];
[imgTab setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin]; imgTab.image=[UIImage imageNamed:@"footerbg.jpg"];
[tabBarController.tabBar addSubview:imgTab];
accountImg=[[UIImageView alloc]initWithFrame:CGRectMake(150.0,5.0,29.0,29.0)];
[accountImg setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
accountImg.image=[UIImage imageNamed:@"click11.png"];
UITabBarItem *tabItem = [[[tabBarController tabBar] items] objectAtIndex:0];
[tabItem setTitle:@"Task"];
[imgTab addSubview:accountImg];
staffImg=[[UIImageView alloc]initWithFrame:CGRectMake(255,5.0,29.0,29.0)];
staffImg.image=[UIImage imageNamed:@"spreadsheet11-1.png"];
UITabBarItem *tabItem1 = [[[tabBarController tabBar] items] objectAtIndex:1];
[tabItem1 setTitle:@"SpreadSheet"];
[staffImg setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
[imgTab addSubview:staffImg];
taskImg=[[UIImageView alloc]initWithFrame:CGRectMake(370.0,5.0,29.0,29.0)];
taskImg.image=[UIImage imageNamed:@"calendar2.png"];
UITabBarItem *tabItem2 = [[[tabBarController tabBar] items] objectAtIndex:2];
[tabItem2 setTitle:@"Calendar"];
[taskImg setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
[imgTab addSubview:taskImg];
spreadImg =[[UIImageView alloc]initWithFrame:CGRectMake(472.0,5.0,29.0,29.0)];
spreadImg.image=[UIImage imageNamed:@"message22.png"];
UITabBarItem *tabItem3 = [[[tabBarController tabBar] items] objectAtIndex:3];
[tabItem3 setTitle:@"Message"];
[spreadImg setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
[imgTab addSubview:spreadImg];
【问题讨论】:
在 ipad 中视图会旋转,但自动调整大小效果不佳,或者视图根本不旋转? 您必须提供更多信息。 我在 iphone 中做了同样的代码,当我在横向模式下工作但在 ipad 中不工作?? 您的代码绝对不可读。我高度怀疑有人会尝试理解它。 这无助于理解问题。首先回答@IvanAlek 的问题。 【参考方案1】:我在此代码中没有看到您正在为您的 UITabBar 配置 UIAutoresizingMask,仅针对其中的项目。
【讨论】:
但我使用的是我在标签栏上应用的图像,您可以在我的代码中看到 请帮帮我。我遇到了麻烦以上是关于带有自动调整大小的 UITabBar的主要内容,如果未能解决你的问题,请参考以下文章
使用带有修复底部 UIView 的自动布局调整 UIView 的大小
iPad - 带有 UITextField 的 UITableView - 方向改变时自动调整大小问题