Swift: How to add Accessibility Identifier on navigation title - ios

In Swift , I am trying to set the Accessibility Identifier on navigation title view using below code -
navigationItem.titleView?.accessibilityIdentifier = "titleview"
But when I check in the Accessible Identifier , it shows none .
I tried to set the navigation title view's accessibilty identifier but it shows none .

Related

Tab bar icon and title not showing with Storyboard References

I have the following storyboard with a segue to a storyboard reference:
The problem is that when I run the app, it doesn't show the icon or the title:
These are the item settings:
What am I missing?
Here's how to get the tab to show properly:
Put the first UIViewController that will be embedded in the tab in
the same storyboard as the UITabViewController.
Ctrl + Drag from the tab bar controller to the content view
controller to make the connection as per usual. This will
automatically add the UITabBarItem to the bottom of the content view
controller.
Select the content view controller.
Click the Editor menu and choose Refactor to Storyboard...
The UITabBarController tab will now point to the new storyboard reference...
... and the content view controller preserves the UITabBarItem from the tab bar relationship. It will appear normally in the app now.
You can modify image/title of the tab bar item in the initial view controller of the storyboard you are referring to. You just need to add a 'tab bar item' to the initial view controller and change its properties (title/image) accordingly.
Outline view of the root view controller in the referred storyboard
The modified tab bar item in the view controller
Note: the change will not be reflected on the tab bar in the main storyboard; you only see it in the referred storyboard and at runtime.
The problem is that in the target view controller, you don't have a UITabBarItem in the views hierarchy. The TabBarItem is related to the storyboard reference, but should be related to the View Controller.
Looks like a "bug" in Xcode...
To resolve this you can do the following:
Just create the segues from the UITabBarController to the Storyboard references.
You may configure the Tab Bar Items in the storyboard references, they don't do much more other than showing the tabs in the tab bar on the Storyboard, which is nice for development purposes.
If you now run the app, you will indeed notice that the tabs are missing.
To get the tabs to display in the running app as well, do this:
Go to the viewcontroller the storyboard reference is referencing to
Add a Tab Bar Item into this View Controller by dragging it from the Object Library into the View Controller
You will now see a tab bar with one single tab in the view controller
Configure the tab bar item to show the correct title and icon
Now run the app and you will now see your tabs.
I tried adding another tab bar, then added tab bar item, selected and image for it BUT Non of above seemed to work with my case ..
it was like this :
Then i compared it with VC that were working properly with TabBar icons..
later i found that my navigation items and tab bar items were not together :
Now its working :):)
After struggling with this problem for a few days I found this solution.
Double click the storyboard link, which will open the referenced storyboard. In the scene navigator, you can edit the bar item with a custom title and icon. Works in xCode 9.
Storyboard
Scene Navigator
I had this exact same issue and neither of the above answers worked in my case. I solved by setting my tab bar image in the image bar item section inside the storyboard's reference like shown in the attached image:
I made following in the storyboard and made class for each UINavigationController
and made following code in each UINavigationController class
override func viewDidLoad() {
super.viewDidLoad()
let someController = StoryboardManager.surveyStoryboard.instantiateViewControllerWithIdentifier("SomeController") as! SomeController
viewControllers = [someController]
// Do any additional setup after loading the view.
}
I did it in different way. My fourth tab was not showing. I just programmatically placed image on its place. You need to set its X,Y coordinates accordingly.
let imageName = "video"
let image = UIImage(named: imageName)
let imageView = UIImageView(image: image!)
imageView.frame = CGRect(x: view.frame.width - 80, y: view.frame.height-70, width: 50, height: 50)
view.addSubview(imageView)
Just add a Tab Bar Item in the "child" view controller:
this works for me

Tab Bar Icon not appearing after setting custom class - iOS

I set the icon set in the storyboard of the Tab Bar Item. This displays fine when that view controller has no custom classes. But as soon as I link it with my Custom Class, it disappears.
How do I get the tab bar to display the icon set that's been set in storyboard??

How to put a title in my Navbar with Xcode and Swift?

I'm developing an app so I need a UINavigationBar. I want to put a title inside of it so I placed a UILabel with the title I want to show. When I run the simulator, it shows everything okay except the title: it doesn't appear. I used constraints to place the UILabel so I guess it's not hidden everywhere. In my Storyboard everything shows fine.
If you're having a navigation controller with your view controller, then you cans et the title using
self.title = #"YOUR_TITLE";
Hope this helps..
Have you tried on a device? Does it still do the same?
Try Adding it directly to the nav bar. Double click the UINavigationBar and add your title
or
Double click UINavigationBar and add it in the Title section that appears in the attributes inspector
Or in code putting labels, buttons on the navigation bar iOS

iOS Navigation Bar - I would like to set the title in Navigation bar with a dynamic value

iOS Navigation Bar - I would like to set the title in Navigation bar with a dynamic value.
Title could be Coffee (xxx cups)
The value of xxx is changed dynamically based on user input.
Thank you.
Somewhere in your view controller code:
self.navigationItem.title = [NSString stringWithFormat:#"Coffee (%d cups)", self.numberOfCupsOfCoffee];
Without more details, I can't be more precise.

navigationItem backBarButtonItem title

Having a issue with navigationItem backBarButtonItem title on a embedded UIViewController.
Im embedding UIViewControllers in scrollview for pagination, and i want to change the back button title for localization when i push something on the stack of scrollview / pagination controller.
This is the code im trying to do in didSelectRowAtIndexPath:
QueryItemTableViewController *itemView = [self.app.storyboard instantiateViewControllerWithIdentifier:#"QueryItemView"];
self.scrollcontroller.navigationItem.backBarButtonItem.title = #"Test";
[self.scrollcontroller.navigationController pushViewController:itemView animated:YES];
The view QueryItemTableViewController is correctly pushed to the navigationcontroller but the title of the back button is still the title from the previous view.
Any suggestions?
Could you please update the title in ViewDidLoad method of the UIViewController which is being pushed.
Set the navigation title in the first one..
As you push to the next view controller. The back button gets set automatically, with the title you have set for the previous.
Now update the Title of the present view controller in the ViewDidLoad .
So simply these are the steps:
Step 1
always set the title for the current view controller in ViewDidLoad to keep uniformity.
step 2
push to the next UIViewController. Everything gets set automatically.
N.B: You wont get any back button for the first view controller (since it is the root view controller). If you need a back button type button there, simply customise a UIBarButtonItem and use it.
The title of the back button will automatically adjust for localization based on the user’s device language settings.

Resources