I need to customize tabBar - xcode

In my project I have two Views with TabBar and I would like to customize each one with different images.
Can anyone know how to do this?

If you are wishing to customize the tabs in your tab bar, that can done by creating a UITabBarItem using the init method below and assigning it to the tabBarItem property of each navigation controller that goes into your tab bar controller. This will display the given titles and images on each tab.
navigationController.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"title"
image:[UIImage imageNamedB:#"tabImage.png"]
tag:0];

Osvaldo, If you want two different backgrounds for the two different view controllers of your tab bar project you have a couple of options. But I would do the following. Grab a UIView from the object library and place one in each vc so that it fills the whole view. Next you can place UIImageViews in the UIView you just placed. Four in the one vc and five in the other. Place them and size them to however you wish. You then need to import the pictures you want to place in them. Drag the image files into the left pane, the project outline. Make sure you copy to destination so they are a part of your project. Next in the vc's click on the UIImageView that you want the picture in. On the right pane under attributes there will be a drop down menu called image. Select the image you want and it will appear in the storyboard in the vc. Do this for all the UIImageViews that you have. When on storyboards, you can pop out the storyboard outline. Make sure the UIImageViews are within the UIView. Then select the UIView in the outline and go up to the editor menu, and select arrange, send to back. It may be grayed out if the UIView was the only thing you had on the vc in the beginning. So now, this UIView will act as a background, and you can customize them to look like anything you like. Hope this helps, let us know how it goes. If it works, please accept my answer, any other questions, just ask.

Related

Create Back Button with Storyboards

I currently have 3 tabs connected to a common UITabBarController. When one of the tabs is selected the user is taken to a UITableView with 3 cells which can be selected. When a cell is selected the user is taken to a new page with a UINavigationBar at the top. My understanding is that the UINavigationBar is supposed to include some sort of back button and I couldn't figure out how to enable it.
In place of the default back button, I dragged a UIButton to the corner and connected it to the 'Show Detail' property of the previous view but when I press the UIButton I am taken to the right UITableView but the tabs are missing for navigation. What am I doing wrong? My segues look like this:
The UINavigationController has the back functionality. How to go back one view in UINavigationController?.
Here is some old tutorial on how to combine that with a tabbarcontroller. should still be the same principles.

UIPage Control custom style NatGeo

In my app I have UIView that flow through the use of a horizontal scrollView. To scroll the view I used the classimo method [self addChildViewController: [self.storyboard instantiateViewControllerWithIdentifier: # "name Storyboard ID"]];
Each UIView is followed through the use of UIPageControl classic, but I do not like it and so I wanted to create something like this (see photo)
as you can see from the images above application there is a menu with a triangle pointing down, Indicating the page, passing from one topic to another user through the horizontal swipe on the scrollView
In other words, instead of having the classic shot for the management of the pages, the National Geographic has used a triangle pointing down and the title of the page on which the user is ...
Could someone help me understand how can 'be created a similar PageControl?
There are a lot of approaches to implement this. Maybe the custom PageControl won't be the subclass of a UIPageControl.
For example, you can subclass a UIView, and put a UIScrollView in it. And then put a bunch of UIButtons in a row into the UIScrollView, each of them has a title that is your page's title. When you tap a button ( you can get this event by UIButton's -addTarget:action:forControlEvents:), you can scroll the tapped button to the right position, highlight it, and put a little triangle below it.
There are many possibilities. Say, you can replace the buttons with UILabel and add UITapGestureRecognizer to capture the users tap, or you can replace the UIScrollView with UITableView if you get a long list of pages(Of course that will introduce some complexity). You just need to pick your favorite and try it out.

How to place objects in tab view in a Xcode mac app?

How do I place objects (i.e. labels or buttons) in a tab view in an Xcode mac app, so that when I click on a different tab the associated objects appear.
For example, I want to be able to put some labels in a tab called "Data" and some buttons in a tab called "Choice". When I press "Data" I want the labels to appear, but the buttons to not, and the other way around as well.
Is there an easy way to do this? Do I need to make a different class for each tab?
Each of the NSTabView's tab consists of as NSView. Here either you can draw all the buttons, labels or any other controls. Even you can add your new view from same xib or load it from other xib.
In the following image you can see, I have used a tabview with two tabs and in the object view you can see two views having two different static text.
And the tab change/click event is fired automatically you dont need to worry about it, the view will be loaded on tab click/change.
Use the built in cocoa view NSTabView which you can find in interface builder:
Each tab has its own view where you can place your objects.

How to show different views in same window in cocoa?

Is it possible to do navigation within the same window in a mac application ?(Like it is possible in ios apps).I want to show each view in the same window instead of opening different windows on a button click.
e.g When a user clicks a button then the next page should be loaded in the same window.(The next page will have nothing in common with the current page.)
You may use Tab View for easy switching between views on a same window.
UPDATE:
You may also customize your tab view , make it tabless (In the attributes inspector set style to tabless) and use your buttons to switch between views.
You may take help from the following link : http://devcry.heiho.net/2012/01/nstabview-tutorial.html
OR
You may add or remove subviews from your window on button clicks, using
[[yourWindow contentView] addSubview: yourSubview]; // Add subview to window
[yourSubview removeFromSuperview]; //Remove subview
UPDATE:
Steps to swap between views using a tabless tab view.
Drag a NSTabView to your xib.
Set the no. of tabs in attribute inspector to no. of views you want.
Design each view of the tab as per your requirement.
Now in the attribute inspector of tabview, set style to tabless.
Now drag the buttons you want to use for swapping between views. Suppose Button0 and Button1 are for 1st and 2nd view of your tab view.
Create a IBOutlet for your NSTabView in your .h file. Bind it to the referencing outlet of you tabview.
IBOutLet NSTabView* tabview;
Set a IBAction for both your buttons in your .h class file.
In the button action method for button1, use
- (IBAction)button1clicked:(id)sender
{
[tab selectTabViewItemAtIndex:0];
}
Similarly in button2 action method use:
[tab selectTabViewItemAtIndex:1];
In this way you can have any no. of views and you may select any view on button click using
[tab selectTabViewItemAtIndex:(index of the view you want to load)];
In general you want to google for view swapping.
There are tons of examples out there. Some from Apple and lots elsewhere.
Much of it is very similar to iOS.
You need to read the docs a bit too.
Understand NSView and how to load views from nibs, how to create view objects in code, how to add a subview and how to remove a view.
There are many approaches to having different views for different reasons. The right approach is a combination of style, experience and what your app actually needs to do.
Cocoa includes NSBox, NSTabView, and lots of others. Those two can be configured to not display any visual indication that they are containers.
You will also need to understand at least a little about NSWindow to understand its content view (the root container of other views generally)

Xcode - Nested storyboard views - hide/show?

I have a reasonably complicated UIView which contains several nested views which are displayed according to a variety of responses - all are laid out in a storyboard.
Is there a way to hide a view in the foreground to work on a view in the background? As its really fiddly selecting particular elements to arrange / style!?
I've been trying to figure out a nice way to do this, some function like hiding the view and its subviews from the storyboard (not from the actual application), but couldn't find anything.
This is not the nicest of ways but it is how I do it at the moment...
What I do is select the views I want to "hide" from the document outline and add a constant (screen width/height) value to its x/y origin value to push them out of the screen. I also change the document label for those views (Identity Inspector > Document > Label) to something like "Hidden" so I can later search for the "hidden" views from the document outline and put them back where they belong.
I have 2 work arounds.
A) Change the View Controllers size to freeform. Set its size to be really large so I can space out the views.
B) Use the sort order of the views Document Outline (lowest is front most) and add an image view (same as the view background) under the first view to block the others. Then delete it after finishing my edits.
or xcode developers could just simple add a design-visible checkbox for views and controls.... but ill take my rants somewhere else.
In xcode 7 you can do it from the storybord
for more details
https://stackoverflow.com/a/25213491/4879683
Maybe this could help you :
Open your storyboard in the Finder and edit it with a simple text editor (not xcode).
You will see it's just a xml file.Look for the view you want to hide, and add hidden="YES" in the parameters list.
That's what I do on my own project.
In Xcode when you select your storyboard, you have a panel that displays all your view controllers and their hierarchy. If you change the order of the elements you change the background/foreground order.
You can add extra views to the scene dock.
These views get initiated along with the view controller, but are not added to the view controller's view hierarchy. You can reference them using IBOutlets.
e.g. I have a full screen loading view that I added to the scene dock instead of covering up the view controller in the storyboard. I can add the loading view to the view controller's view hierarchy in code:
#IBOutlet weak var loadingView: UIView!
...
loadingView.frame = view.bounds
loadingView.autoresizingMask = UIViewAutoresizing.FlexibleWidth.union(UIViewAutoresizing.FlexibleHeight)
view.addSubview(loadingView)
Reference: https://developer.apple.com/library/ios/recipes/xcode_help-IB_storyboard/Chapters/AddViewsToDock.html

Resources