This is my setup for a tab bar item:
However when clicking on the item inside the app the 1051-id-badge-selected image is not shown, instead nothing is shown:
Is something wrong with my setup? Any ideas?
To get around this issue and set selected image without writing any code, we can also use "User Defined Run Attributes".
Select the tab bar item, then in 'Identity Inspector', add a new value from 'User Defined Runtime Attributes'.
Set the 'Key Path' to selectedImage, and choose 'Type' Image, then fill in the 'Value' with your image name.
If the inspector solution is not working for you (e.g. because of an Xcode bug) you can try this solution. In AppDelegate:
var tabBarController = self.window!.rootViewController as UITabBarController
let tabItems = tabBarController.tabBar.items as [UITabBarItem]
tabItems[2].selectedImage = UIImage(named: "1051-id-badge-selected.png")
Update on May 25, 2016:
On Xcode 7.3.1 the Selected Image field under Tab Bar Item section is working correctly. (But I don't know from which exact version Apple fixed it for Xcode).
Related
I am facing a weird problem i.e:
My Button title is not what i mentioned in storyboard after build.The Button is getting title from other button near to it.
What i tried already is:
I have verified that Object ID of both button are different.
I clean the project and built again.
I Uninstalled the app and from simulator and tried again.
I restarted the Xcode and checked again.
And Also from code i am not changing title of any button infect no ref# or outlet in code.
If i remove the title from storyboard and Run it reflect the change and show empty title there! that is Normal behaviour, But when i put any other title it show nearest element title not own.
Also if i set title from Controller [self.basicInfo setTitle:#"Basic Info" forState:UIControlStateNormal];it change the text and solves the issue.
But My Point is why it is behaving like this and where is the problem.
I have Attached the image file where you can see that in storyboard it show text "Basic information" but after running it shows HOW TO BUY.
Your problem is related to the fact that you have your storyboard localized, so you need to search in your (StoryBoardName.string) the Label object id ie: "YR7-n7-RFZ.text" = "testText"; and change the value after equal sign
here you have an tutorial about this topic
https://medium.com/lean-localization/ios-localization-tutorial-938231f9f881
I am working on an app in Xcode. I currently have three tabBarItems on my tab bar. I want the middle one to be a picture chosen by the user. I have the desired picture in a variable and i have the tabbar.swift set up to put the code in. I just need to set the image to the variables image with correct size (and make the picture appear as a circle) and the title name to a string.
Any help in doing this would be much appreciated. Thanks
Try this code.
self.tabBarController?.tabBar.items![0].image = UIImage(named: "your image name")
// items![0] index of your tab bar item.items![0] means tabbar first item
self.tabBarController?.tabBar.items![0].selectedImage = UIImage(named: "your image name")
I want the Contact icon on the left, what is the easiest way to do this?
EDIT: I found a simple solution.. I just had to delete the link between my Tab Bar Controller and the Bookmark page, then reconnect it to set it as second icon (on the right). See image: prntscr.com/b0hucd
Drag and drop should work
You can drag the contacts bar Item to the left to rearrange its position from the Storyboard.
Try this code i used it to move the image in tabbar items to move vertically up.In this loop check that the index is 1 else it will move the bookmark icon also
for (UITabBarItem * item in tabBarController.tabBar.items) {
item.image=[item.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item.imageInsets=UIEdgeInsetsMake(item.imageInsets.top, item.imageInsets.left+20, item.imageInsets.bottom, item.imageInsets.right-20);
}
Note: If it doesn't move the text let me know
UITabBar Class Reference
Check out the "items" property. (emphasis mine)
This property contains an array of UITabBarItem objects, each of which corresponds to a tab displayed by the tab bar. The order of the items in this property corresponds to the order of the items onscreen. You can use this property to access the items as needed.
I have set in Storyboard tab bar item to be Custom, Image to my outline image and Selected image to my filled image but the selected image does not show up when I run the app.
It works if I create a tab bar item programmatically using
UITabBarItem(title: String?, image: UIImage?, selectedImage: UIImage?)
I use Xcode 6.1.1.
What can be wrong?
I think, it is a bug of Xcode, if you add a user defined runtime attribute with type Image and keyPath "selectedImage", you'll can set your image.
Here example of the Tabbed Application template with a custom selected image on the second tab (I use a image from the first tab):
This is more than likely because it doesn't meet the interface requirements. Tab bar items are picky, the strokes or outlines for a selected image have to be noticeably greater than its counterparts. See here specifically the notes about the stroke width. Conditionally, if it's not a 'filled' in variation of your unselected image it has a chance of not populating depending on you create the selected image in comparison.
As of Xcode 9, the functionality to set a selected image is available (and works) in interface builder.
In Xcode 6, you now have the ability to set the icon for a tab item for its selected and unselected states. Please see the descriptions in the images below:
and
The only problem is that the image for the SELECTED states does not show. It just shows blank. Anyone else have this issue? Please see the screenshots below of the results:
and
Thanks!!!
So the way to go around this:
Set the tab with the default, unselected icon image you want to use in the "BAR ITEM" section in the Attributes Inspector:
Click on the Identity Inspector, and under "USER DEFINED RUNTIME ATTRIBUTES," click the + to add a new value.
KEYPATH: selectedImage (IT HAS TO BE THIS!!!)
TYPE: Image
VALUE: The name of your selected/highlighted icon image. I use Images.xcassets for my image assets.
Run your app. You'll notice that the image changes to the selected (not just highlighted version of it.
Works like a charm.
I want to add some info about the colored tab icon.
To change tab selection color:
Select the tabItem.
Set "tintColor" attribute with your prefer color.