我正在尝试以编程方式为我的应用中的标签栏设置背景图片.我的代码如下:
RootViewController.h
IBOutlet UITabBar *mainTabBar;
IBOutlet UITabBarItem *settingsBarItem;
IBOutlet UITabBarItem *infoBarItem;
IBOutlet UITabBarItem *aboutBarItem;
Run Code Online (Sandbox Code Playgroud)
RootViewController.m
-(void)viewDidLoad {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"smallMenuBackground.png"]];
[mainTabBar insertSubview:imageView atIndex:0];
[imageView release];
[super viewDidLoad];
}
Run Code Online (Sandbox Code Playgroud)
这不适合我.
UPDATE
更新2012年1月23日
好的,我已经取得了一些进展.自从我升级到Xcode 4.2和IOS5后,这才停止工作.我设法使用Interface Builder中的选项将其恢复,但现在它仅适用于IOS5.理想情况下,我希望以编程方式开始工作,但我现在将满足于IB解决方案.
我似乎无法让它适用于任何以前的版本.
注意:我的TabBar只在我的RootViewController上,这是我的应用程序的主屏幕.
理想情况下,如果我能让Nithin建议的代码正常运行,那就太棒了:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabBG.png"]];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
//iOS 5
[self.tabBarController.tabBar insertSubview:imageView atIndex:1];
}
else {
//iOS 4.whatever and below
[self.tabBarController.tabBar insertSubview:imageView atIndex:0];
}
[imageView release];
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
问候,斯蒂芬
我在这里要完成的是合并这两个教程(x)(x),以创建一个具有自定义图标的简单TabBar.我正在尝试使用react-native-vector-icons库中的图标,我已将其添加到我的节点模块中.但是,我遇到了一个障碍:
不变违规:元素类型无效:期望一个字符串(对于内置的>组件)或一个类/函数(对于复合组件)但得到:undefined.您可能忘记从其定义的文件中导出组件,或者您可能混淆了默认导入和命名导入.
检查ProfileTabs的render方法.
此错误位于:在RCTTabBar中(在TabBarIOS.ios.js:82)
在TabBarIOS中(在App.js:19)
在ProfileTabs中(在App.js:80)
在ProfileApp中(在registerRootComponent.js:35)
在RootErrorBoundary中(在registerRootComponent.js:34)
这是相关的代码:
import React, { Component } from 'react';
import { AppRegistry, Image, StyleSheet, TabBarIOS, Text, View } from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons';
var Profile = require('./profile');
var Repositories = require('./repositories');
var Following = require('./following');
var Followers = require('./followers');
class ProfileTabs extends Component {
constructor(props) {
super(props);
this.state = {
selectedTab: 'profile'
};
}
render() {
return (
<TabBarIOS
selectedTab={this.state.selectedTab}>
<Icon.TabBarIOS
selected={this.state.selectedTab === 'profile'}
title="Profile"
iconName='ios-home-outline'
onPress={() => { …Run Code Online (Sandbox Code Playgroud) 刚刚发现了一些东西:如果你有一个Tabbar与一个NavigationController(它有一些堆栈的视图)相结合,你双击TabBarItem,视图弹出到第一个ViewController,无论你喜欢与否.
有办法防止这种情况吗?
我在我创建的Tab Bar控制器的自定义子类中有一个Nav控制器.
每当显示的控制器中的一个试图隐藏或显示标签栏时,我想从(自定义)标签栏中知道.(例如,将具有hidesBottomBarWhenPushed = YES的VC推送到Nac控制器上时).
总之,我希望收到隐藏/显示标签栏的事件的通知,但在Apple的参考资料中找不到任何内容.我尝试查看UITabBar,UITabBarDelegate,UITabBarController和UITabBarControllerDelegate,但似乎只提供与标签栏项相关的功能.
提前致谢.
我通过设置每个项目的图像创建了一个简单的自定义标签栏,如下所示:
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
[item0 setFinishedSelectedImage:[UIImage imageNamed:@"activity_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"activity.png"]];
[item1 setFinishedSelectedImage:[UIImage imageNamed:@"agenda_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"agenda.png"]];
[item2 setFinishedSelectedImage:[UIImage imageNamed:@"settings_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"settings.png"]];
Run Code Online (Sandbox Code Playgroud)
虽然这很好用,但我注意到我的tabbar下面有一个黑色的空白区域

我的图像高度为44像素,但我想我必须以某种方式改变我的标签栏的高度.
我在设置分隔符的drawable时遇到问题.我的style.xml看起来像这样:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="HCLTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/HCLActionBarStyle</item>
<item name="actionBarStyle">@style/HCLActionBarStyle</item>
<item name="android:actionBarTabBarStyle">@style/HCLActionBarTabBarStyle</item>
<item name="android:actionBarTabStyle">@style/HCLActionBarTabStyle</item>
</style>
<style name="HCLActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
<item name="android:background">@drawable/hcl_actionbar_drawable</item>
<item name="background">@drawable/hcl_actionbar_drawable</item>
<item name="android:titleTextStyle">@style/HCLActionBarTitle</item>
</style>
<style name="HCLActionBarTabBarStyle" parent="@android:style/Widget.Holo.ActionBar.TabBar">
<item name="android:showDividers">middle</item>
<item name="android:divider">@drawable/divider</item>
<item name="android:dividerPadding">0dp</item>
</style>
<style name="HCLActionBarTabStyle" parent="@android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">@drawable/action_bar_tab_style</item>
</style>
<style name="HCLActionBarTitle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@android:color/white</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
在HCLActionBarTabBarStyle中,我将@ drawable/divider设置为制表符分隔符.这个drawable是一个9patch图像,一个垂直的黑色线条.
在我在xml中设置可绘制的分隔符之前我得到了正常的白色分隔符,如下所示:

在styles.xml中设置drawable之后我得到了这个:

因此,您可以看到分频器变得更宽,而不是9patch图像中的黑色垂直线.我甚至不确定分隔器的抽屉是什么?图片或图层列表,还是可以是颜色?事实上,我尝试了所有这3个但没有成功.
我正在使用基于xib的视图,并以编程方式为tabbar创建视图控制器.我也在使用ios 7,当我尝试执行手势或更改标签时,我不断收到此消息,当然标签不会更改视图....
有谁知道发生了什么?我搜索谷歌并没有出现任何问题.
2014-09-11 16:28:38.730 Deskercise [30056:1497359] _UIApplicationHandleEventFromQueueEvent,_windowServerHitTestWindow中的意外nil窗口:; layer =>
答案:在每个视图控制器中使用self.tabBarController?.tabBar.hidden而不是hidesBottomBarWhenPushed来管理视图控制器是否应显示标签栏.
override func viewWillAppear(animated: Bool) {
self.tabBarController?.tabBar.hidden = true/false
}
Run Code Online (Sandbox Code Playgroud)
我想要
视图控制器1:应显示标签栏
视图控制器2:应显示标签栏
视图控制器3:不应显示标签栏.
视图控制器4:不应显示标签栏.
我写
// prepareForSegue in view controller 1,
let upcoming = segue.destinationViewController as! viewcontroller3
upcoming.hidesBottomBarWhenPushed = true
// in view controller 3,
func clickOnButton(button: UIButton) {
self.hidesBottomBarWhenPushed = false
self.performSegueWithIdentifier("viewController2", sender: self)
self.hidesBottomBarWhenPushed = true
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "viewController2" {
let upcoming = segue.destinationViewController as! viewController2
upcoming.hidesBottomBarWhenPushed = false
}
}
// prepareForSegue in view controller 2
let …Run Code Online (Sandbox Code Playgroud) 我有一个包含项目列表的 TabBarView,我为每个项目分配了一个 Navigator.push 方法。目前这个方法会跳转到一个新页面。
我的问题是,是否可以导航到 TabBarView 主体内的新页面?这意味着我想导航到另一个页面,同时将所有顶部应用栏和 BottomNavigationBar 保留在屏幕上。
我想使用新的 iOS 16 Buttom Sheet 功能来创建类似查找我的视图:
不幸的是,TabView 隐藏在工作表后面:
我的代码:
TabView {
Text("View 1")
.sheet(isPresented: .constant(true)) {
Text("Sheet View Content")
.presentationDetents([.medium, .large])
}
.tabItem {
Label("Menu", systemImage: "list.dash")
}
Text("View 2")
.tabItem {
Label("Order", systemImage: "square.and.pencil")
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现这个目标?