当我使用这个方法来初始化一个UITabBarItem:
- (id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag
Run Code Online (Sandbox Code Playgroud)
我是否需要为每个标签栏项目使用不同的标签,或者(因为我不使用它们)我可以简单地为所有标签使用相同的标签值吗?
@IBAction func addToCart(sender: AnyObject) {
let itemObjectTitle = itemObject.valueForKey("itemDescription") as! String
let alertController = UIAlertController(title: "Add \(itemObjectTitle) to cart?", message: "", preferredStyle: .Alert)
let yesAction = UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default) { (action) in
var tabArray = self.tabBarController?.tabBar.items as NSArray!
var tabItem = tabArray.objectAtIndex(1) as! UITabBarItem
let badgeValue = "1"
if let x = badgeValue.toInt() {
tabItem.badgeValue = "\(x)"
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么我不能做+ ="(x)"
错误:二元运算符'+ ='不能应用于'String?'类型的操作数 和'字符串'
我希望每次用户选择"是"时它增加1.现在显然它只停留在1.
我希望有人能解释我如何做到这一点:
我有一个TabBar和两个TabBarItems,我如何将项目附加到TabBar.我不是通过IB做这个,因为TabBar只适合屏幕,因为项目应该在左侧.
多数民众赞成我如何建立它们:
tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
tabBarController2 = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
tabBarController.tabBar.frame = CGRectMake(0, 974, 384, 50);
tabBarController2.tabBar.frame = CGRectMake(384, 974, 384, 50);
UITabBarItem *tbi1 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:0];
UITabBarItem *tbi2 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:1];
Run Code Online (Sandbox Code Playgroud) 我的iphone应用程序中有一个tabbar控制器.一切都很好,直到单击第二个tabbar项.单击它时,第二个选项卡的标签栏图标下的tabbaritem标题/名称将消失.但是第一个标签没有问题.
有谁知道这是什么原因.
我正在使用UITabBarItem.如果我设置图像,它没有正确显示.图像被"缩放",所以我只能看到它的顶部.图像大小为60x60px.
我从xcodes XIB编辑器 - > BarItem - > Image设置图像
它出什么问题了 ?根据Apple Doc的说法,Retina的图像应该是60x60,甚至更大的图像应该自动缩放以适应观看区域.
我创建了一个基于标签的应用,它有5个标签.
我希望第三个标签栏项目的高度高于所有其他标签.
此第三个标签栏项的大小将始终保持大于其他标签.
如何在基于选项卡的应用程序中执行此操作?没有自定义标签栏可以吗?
请帮忙
提前致谢
我有我的应用程序一个奇怪的问题:我有一个UIViewController是目前的UIAlertView当用户点击一个按钮.警报让用户在照片库和iPhone相机之间进行选择.
当警报出现时,我注意到这个问题:
首先,UIViewController选定的标签栏项目具有此布局

然后,当警报出现时,它会像这样改变

如果用户决定访问他的照片库然后返回,则标签栏项目仍然如下所示

怎么可能?也许UIAlertView正在改变一些色彩?
谢谢
我试图更改未选中的UITabBarItems的默认灰色.我设法改变了文本而不是图像.

TabBar.appearance().barTintColor = UIColor(red: 86.0/255.0, green: 132.0/255.0, blue: 208.0/255.0, alpha: 1.0)
var normalTint: UIColor = UIColor.whiteColor()
TabBar.appearance().tintColor = UIColor.whiteColor()
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: normalTint,NSFontAttributeName: UIFont(name: "Arial", size: 13)!], forState: UIControlState.Normal)
Run Code Online (Sandbox Code Playgroud) 在我更新到Swift 3之前,这非常有效(除了启用了isEnabled).这段代码在我的UITabBarController ViewDidLoad函数中.该if是从来没有遇到过这么因此项目永远不会设置为true.
我如何访问这些项目,因为我希望选项卡显示为灰色,直到选择变量为止?
if let arrayOfTabBarItems = self.tabBar.items as AnyObject as? NSArray,let tabBarItem = arrayOfTabBarItems[1] as? UITabBarItem {
tabBarItem.isEnabled = true
}
Run Code Online (Sandbox Code Playgroud) uitabbaritem ×10
ios ×5
uitabbar ×5
iphone ×3
objective-c ×3
swift ×2
swift3 ×2
badge ×1
cocoa-touch ×1
count ×1
ios7 ×1
ipad ×1
swift2 ×1