iOS navigation bar with "tab like" functionality/buttons - objective-c

What would be the best way to make these buttons? I have no problem with the right/left buttons, but this "tab" functionality is eluding me.
I was thinking of adding custom buttons on viewDidLoad like:
UIButton *profileBtn = [[UIButton alloc] initWithFrame:CGRectMake(50, 5, 100, 30)];
[profileBtn setTitle:#"Profile" forState:UIControlStateNormal];
[self.navigationController.navigationBar addSubview:profileBtn];
However, then the buttons stay on the navigation bar until I manually get them off. Surely there is a better/easier way to do something like this? (note that I'm already using the UITabBarController on the bottom of the screen)

Make use of the UISegmentedControl. Switch views by adding both in the first place and hide/show accordingly. If that eats up too much memory create them just in time and remove the inactive one from the superview.
Here is a tutorial on the UISegmentedControl.

Related

Iphone uibutton click feel

My problem is I have to change UIButton backgroundcolor on click and navigation controller move to next page.
I don't need to use NSTimer to show button effect.
I need to apply this effect for my application all buttons.
I can't able to make my next view controller to wait for show this effect.
If I understand what you're asking correctly, you want all buttons in your application to instantly change background colors upon a button click. You can do this using the UIButton's appearance.
In short, UIAppearance allows developers to easily keep visuals consistent throughout their applications. For more information on what it is and how to use it, click here.
Here's an example:
//Inside of an IBAction that a button clicks
[[UIButton appearance] setBackgroundColor:[UIColor redColor]];

On iOS7, bar button item icons vanished in input accessory view

Moving my app from iOS6.1 to iOS7, all the button that were visible under iOS6.1 in the toolbar I created for the Input Accessory View of the keyboard are not visible anymore (but still active).
I tried all combinations of [myBar setTranslucent:...] and [myBar setBarStyle:...] but no way to make these buttons visible again. They are defined as:
UIBarButtonItem *myButton =[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"myImage.png"] style:UIBarButtonItemStylePlain target:self action:#selector(mySelector:)];
<-iOS 7.1
<-iOS 6.1
Any idea? Thanks!
I found the solution of my problem.
The method I used to remove the standard input accessory view of the uiwebview was the reason of this problem, it left some view displayed that prevented from seeing the new UIToolbar view. I used the one described here in Stackoverflow and it works.

Background image of back button does not appear before it is touched iOS 7

I am experiencing some problems with [UIBarButtonItem appearance] for the the back button background image.
Normally (iOS 5 and iOS 6) I was able to set the background image of the back button like this:
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
But at iOS 7 the background image does not appear on the back button. The weird thing is, that the background image actually appears when the back button has been touched once.
I have tried setting the image for all states, to test if iOS 7 was using some kind of new state for an untouched back button, but that does not seem to be the case.
Do you have any idea, what I am doing wrong?
A solution which will make the background appear correctly on iOS7 is at OS 7 custom back button. It swizzles a method to fix the Apple bug (which is that they forget to call setNeedsDisplay on the private view when the background image is changed). Going borderless is probably better, if possible, but swizzling does work.
I searched for this problem and found that you are not the only one to have the same problem. There are many others who face the same issue with UIAppearance. These are the proofs (to explain you to your client) :
UIBackButton Background Image not appearing
Back button is not visible in iOS 7
In this case, what you can do is to follow the Answer provided in the 2nd Link.
You can either set the backIndicatorImage property on UINavigationBar to a custom image or you can change the color of the backIndicatorImage by setting the tintColor property on UINavigationBar.
You can create a custom UIBarButtonItem and manually assign it as UINavigationItem's leftBarButtonItem.
try to change the tint color of the button. There is some issue in iOS 7 for UIBarButton
I implemented a really nice solution that works under ios5+ here:
Back button item strangely disappearing under iOS7
To work with ios7 you need to use
UIImage *backButton = [[UIImage imageNamed:#"icon_back" resizableImageWithCapInsets:UIEdgeInsetsZero];
if ([UINavigationBar instancesRespondToSelector:#selector(setBackIndicatorImage:)]) {
[[UINavigationBar appearance] setBackIndicatorImage:backButton];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backButton];
}else{
//ios 5 and 6 code
}

UIButton not receiving touches when added to subview, but does when added to main view

Basically I have a main screen that comes up with a background image and three menu choices across the bottom of the screen. When I add these 4 components to the RootViewController's view, everything works fine., but if I do something like
_mainContainer = [[UIView alloc] init];
self.view = _mainContainer;
_firstScreen = [[UIView alloc] initWithFrame:self.view.frame];
"some code here setting up the subviews"
[buttonLeft addTarget:self action:#selector(startGame) forControlEvents:UIControlEventTouchUpInside];
[_firstScreen addSubview:mainMenuBackground];
[_firstScreen addSubview:buttonLeft];
[_firstScreen addSubview:buttonMid];
[_firstScreen addSubview:buttonRight];
[_mainContainer addSubview:_firstScreen];
Essentially if I add everything directly to _mainContainer, the buttons work, if I add it to _firstScreen, then add _firstScreen they don't work.
User interaction is enabled on _firstScreen. I do something similar later in my app and it works fine. Also, not sure if this has anything to do with it, but despite my screen being displayed in landscape, and all options in the plist being set to landscape only, when I run a transition, like flipFromBottom (or whatever its called), my app thinks the "bottom" is with the screen being in portrait until I move to another group of subviews in my app. (So basically the title screen is acting screwy).
I looked everywhere for a solution, hopefully I am not missing something basic.
Hey what is mainMenuBackground?, if its a image , their is no need to make it as a subView, instead, the correct way is to set it as a background image. I hope this will solve your problem

Can I use IOS5 Appearance in only some cases, to preserve the back arrow?

I am using the appearance protocol [[UIBarButtonItem appearance] setTintColor:[UIColor blueColor]]; to color all my buttons. The problem I am running into is that there are some rare cases where I have to create a custom back button like so, UIButton* customBack = [UIButton buttonWithType:101];, inorder to have it callback to an event when pressed. When I use the appearance protocol it removes the arrow shape.
Does anyone know a way to get back the arrow shape? Or is there a way to specify in the appearance to not effect a certain class?
The only accepted way I know of is to use an image. Also, I think you should be using [UIButton buttonWithType:UIButtonTypeCustom] instead of the numeric value.