我使用UITabBar和UITabBarItems用它。我可以UITabBarItem在分配tabBarItem给之前设置徽章值tabBar。但我的问题是我无法更新tabBarItem.
这是我最初可以设置徽章值的代码:
// array of tabBarItems
NSMutableArray * tabs = [[NSMutableArray alloc] init];
for(iterates few times)
{
[tabs addObject:[[UITabBarItem alloc] initWithTitle:firstName image:nil tag:i]];
// set tabItem's property
[(UITabBarItem *)[tabs objectAtIndex:i] setFinishedSelectedImage:[self convertImage:iconImage toSize:CGSizeMake(iconWidth, TAB_ICON_HEIGHT)] withFinishedUnselectedImage:[self convertImage:iconImage toSize:CGSizeMake(iconWidth, TAB_ICON_HEIGHT)]];
[[tabs objectAtIndex:0] setBadgeValue:[NSString stringWithFormat:@"%d", 2]];
}
// setting items of UITabBar
[self.chatTabBar setItems:tabs];
Run Code Online (Sandbox Code Playgroud)
在这里,我尝试更新徽章值。所以发生的情况是,如果我NSLog使用新的徽章值,它会显示更新的值,但我看不到 UI 的变化。
[[self.chatTabBar.items objectAtIndex:0] setBadgeValue:[NSString stringWithFormat:@"%d", 1]];
Run Code Online (Sandbox Code Playgroud) 我找到了很多示例,展示了如何从 UIBarButtonItem 呈现弹出框,但我想知道如何从 UITabBarItem 呈现它。
这是我到目前为止所拥有的
let selectedItem = self.menuTabBar.items![3]
let menuViewController: ActivityPopoverViewController = storyboard.instantiateViewControllerWithIdentifier("MenuViewController") as! ActivityPopoverViewController
presentViewController(menuViewController, animated: true, completion: nil)
menuViewController.modalPresentationStyle = .Popover
if let popoverMenuViewController = menuViewController.popoverPresentationController {
popoverMenuViewController.permittedArrowDirections = .Any
popoverMenuViewController.delegate = menuViewController
// popoverMenuViewController.barButtonItem = ?
}
Run Code Online (Sandbox Code Playgroud)
我试图将作为 UITabBarItem 的 selectedItem 转换为 UIBarButtonItem ,但这没有用。我确定这是一个简单的过程,但我似乎无法找到有关如何执行此操作的任何帮助。
我的目标是让这个橙色弹出框指示未读活动。
更新#1。在做了更多的研究之后,我发现了这种呈现视图控制器的策略
let tabBarItemWidth = Int(self.menuTabBar.frame.size.width) / (self.menuTabBar.items?.count)!
let x = tabBarItemWidth * 3;
let newRect = CGRect(x: x, y: 0, width: tabBarItemWidth, height: Int(self.menuTabBar.frame.size.height))
print(newRect)
let menuViewController: ActivityPopoverViewController = storyboard.instantiateViewControllerWithIdentifier("ActivityPopoverViewController") …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的 iOS 应用程序实现底部导航栏。但是,当我创建 tabBarItem 时,它没有显示在 TabBar 上。TabBar 显示正确。我无法弄清楚问题出在哪里,任何帮助将不胜感激。
如果需要任何其他信息,请给我一个标志。我的代码(简化):
应用委托:
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = TabBarController()
return true
}
}
Run Code Online (Sandbox Code Playgroud)
标签栏控制器:
class TabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let homeController = HomeController()
let navigationController = UINavigationController(rootViewController: homeController)
navigationController.title = "Home"
navigationController.tabBarItem.image = UIImage(named: "icon")
viewControllers = [homeController]
}
}
Run Code Online (Sandbox Code Playgroud)
家庭控制器:
class HomeController: UIViewController …Run Code Online (Sandbox Code Playgroud) 我想减少 UITabBarItem 与其文本之间的垂直填充:
即为了使它看起来像这样:
我试过这个代码:
let pStyle = NSMutableParagraphStyle()
pStyle.lineSpacing = -10.0
UITabBarItem.appearance().setTitleTextAttributes([.paragraphStyle: pStyle], for: .normal)
Run Code Online (Sandbox Code Playgroud)
但它没有用。想法?
TvOS 13. 我有一个带有选项卡的 UITabBarController。并且可以自定义几乎所有东西,除了这个明显的东西:聚焦标签的背景。它总是白色的。
指南告诉
为选定和未选定的项目指定色调
我试过:
view.backgroundColor = .purple
tabBar.tintColor = .yellow
tabBar.barTintColor = .red
tabBar.unselectedItemTintColor = .brown
tabBar.backgroundColor = .green
tabBar.backgroundImage = UIColor.blue.toImage()
tabBar.shadowImage = UIColor.orange.toImage()
tabBar.selectionIndicatorImage = UIColor.burgundy.toImage()
Run Code Online (Sandbox Code Playgroud)
没有任何帮助。
有没有办法使用UITabbaritem作为UIButton?我正在尝试制作一个Tabbar,其项目不会更改视图.只是希望他们在同一个视图控制器中执行简单的操作.
谢谢.
我正在研究uitabbar应用程序的定向工作.我在tabbar中使用5个tabbar项.我想在Landscape和potrait中只旋转4个标签栏项目.但问题是当我在非旋转标签栏项目中将"返回否"添加到shouldAutorotateToInterfaceOrientation时,所有标签栏都不起作用.任何人都可以告诉我我错了什么?
提前致谢.
问候,sathish
我通过情节提要设置了四个选项卡项目,但是我只想通过编程方式设置一个选项卡栏,因为我希望最后一个选项卡栏项目成为我的个人资料图片。有没有一种方法可以在ProfileViewController中以编程方式仅设置一个选项卡栏项目,而不必以编程方式设置其他三个选项卡栏项目。
我想将其设置为选项卡项,但是它变成空白:
override func awakeFromNib() {
super.awakeFromNib()
self.tabBarItem.title = "MY ACCOUNT"
// self.tabBarItem.image = UIImage(named: "Speech Bubble Filled-50")
if let postProfile = self.loggedInUserUid {
let imageRef = FIRStorage.storage().reference().child((loggedInUserUid)!+"/profile_pic.jpg")
imageRef.data(withMaxSize: 1 * 1024 * 1024, completion: { (data, error) -> Void in
if error != nil {
print(error)
return
}
DispatchQueue.main.async(execute: { () -> Void in
let image = UIImage(data: data!)
self.tabBarItem.image = image
})
}).resume()
}}
Run Code Online (Sandbox Code Playgroud) 我已经尝试了很多东西,但是找不到一种方法来将UITabBarItem的标签放置为自定义的lineNumber.0(我希望在2行上获得标题).
有办法吗?
uitabbaritem ×10
ios ×6
swift ×6
uitabbar ×4
iphone ×3
ios6 ×1
objective-c ×1
orientation ×1
popover ×1
rotation ×1
tvos ×1
tvos13 ×1
uibutton ×1
uikit ×1
uitabview ×1