I am using ZUUIRevealController Library.
Appdelegate.h file
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
UITabBarController *tabBarController=[[UITabBarController alloc]init];
FrontViewController *frontViewController = [[FrontViewController alloc] init];
RearViewController *rearViewController = [[RearViewController alloc] init];
MapViewController *frontViewController2 = [[MapViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:frontViewController2];
RevealController *revealController = [[RevealController alloc] initWithFrontViewController:navigationController rearViewController:rearViewController];
RevealController *revealController2 = [[RevealController alloc] initWithFrontViewController:navigationController2 rearViewController:rearViewController];
[revealController.tabBarItem setTitle:#"Home"];
[revealController2.tabBarItem setTitle:#"Absent note"];
revealController.tabBarItem.image=[[UIImage imageNamed:#"home_icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
revealController2.tabBarItem.image=[[UIImage imageNamed:#"absent_note_icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[tabBarController setViewControllers:[NSArray arrayWithObjects:revealController,revealController2,nil]];
[self.window setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
return YES;
}
FrontViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = NSLocalizedString(#"Front View", #"FrontView");
if ([self.navigationController.parentViewController respondsToSelector:#selector(revealGesture:)] && [self.navigationController.parentViewController respondsToSelector:#selector(revealToggle:)])
{
UIPanGestureRecognizer *navigationBarPanGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self.navigationController.parentViewController action:#selector(revealGesture:)];
[self.navigationController.navigationBar addGestureRecognizer:navigationBarPanGestureRecognizer];
[self.view addGestureRecognizer:navigationBarPanGestureRecognizer];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"Slide", #"Slide") style:UIBarButtonItemStylePlain target:self.navigationController.parentViewController action:#selector(revealToggle:)];
}
}
RearViewController is a Table ViewController
MapViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = NSLocalizedString(#"Map View", #"MapView");
if ([self.navigationController.parentViewController respondsToSelector:#selector(revealGesture:)] && [self.navigationController.parentViewController respondsToSelector:#selector(revealToggle:)])
{
UIPanGestureRecognizer *navigationBarPanGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self.navigationController.parentViewController action:#selector(revealGesture:)];
[self.navigationController.navigationBar addGestureRecognizer:navigationBarPanGestureRecognizer];
[self.view addGestureRecognizer:navigationBarPanGestureRecognizer];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"Slide", #"Slide") style:UIBarButtonItemStylePlain target:self.navigationController.parentViewController action:#selector(revealToggle:)];
}
}
Tabs working Properly, but the sliding menu not working properly.
First I am click the Home tab and Slide menu to view the slide Viewcontroller.Next I clicked the Second tab and sliding menu to view the slide Viewcontroller. Again I've clicked the Home tab and sliding menu to view the Slide Viewcontroller. It cannot displayed only display a black screen.
I found the solution for that problem.
in Appdelegate file i have written the swreavealtoggle call for navigation.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
HomeViewController *frontViewController = [[HomeViewController alloc] init];
SlideViewController *rearViewController = [[SlideViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;
self.viewController = revealController;
[self.window setRootViewController:self.viewController];
[self customizeInterface];
[self.window makeKeyAndVisible];
return YES;}
Then create a viewController to add a Tabbar item components.
Myviewcontroller name is HomeViewController.h
after i include the tab item button click action
#import <UIKit/UIKit.h>
#interface HomeViewController : UIViewController<UITabBarDelegate>{
UITabBar *mainTabBar;
UIViewController *tab1vc; // view controller of first tab
UIViewController *tab2vc; // view controller of second tab
UIViewController *tab3vc; // view controller of first tab
UIViewController *tab4vc; // view controller of second tab
}
#property (nonatomic, retain) IBOutlet UITabBar *mainTabBar;
#property (nonatomic, retain) UIViewController *tab1vc;
#property (nonatomic, retain) UIViewController *tab2vc;
#property (nonatomic, retain) UIViewController *tab3vc;
#property (nonatomic, retain) UIViewController *tab4vc;
#end
HomeViewController.m
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
// item is the selected tab bar item
switch (item.tag) {
case 1:
if (tab1vc == nil) {
self.tab1vc =[[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil];
}
[self.view insertSubview:tab1vc.view belowSubview:mainTabBar];
self.title = #"Home";
label.text = self.title;
//[tab1vc release];
NSLog(#"1st");
break;
case 2:
if (tab2vc == nil) {
self.tab2vc =[[Tab2 alloc] initWithNibName:#"Tab2" bundle:nil];
}
[self.view insertSubview:tab2vc.view belowSubview:mainTabBar];
//[tab2vc release];
self.title = #"Tab2";
label.text = self.title;
NSLog(#"2st");
break;
case 3:
if (tab3vc == nil) {
self.tab3vc =[[Tab3 alloc] initWithNibName:#"Tab3" bundle:nil];
}
[self.view insertSubview:tab3vc.view belowSubview:mainTabBar];
//[tab2vc release];
self.title = #"Tab3";
label.text = self.title;
NSLog(#"3rd");
break;
case 4:
if (tab4vc == nil) {
self.tab4vc =[[Tab4 alloc] initWithNibName:#"Tab4" bundle:nil];
}
[self.view insertSubview:tab4vc.view belowSubview:mainTabBar];
//[tab2vc release];
self.title = #"Tab4";
label.text = self.title;
NSLog(#"4th");
break;
default:
break;
}
}
Now its working good
Related
When I add a view controller embedded by navigation controller, to a tab bar, its icon + title disappear briefly when coming back to the More tab.
However when the view controller is added as such, the icon+image are okay and don't disappear.
I've tried many things already, and am out of options. Any ideas?
Here's my AppDelegate code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.tabBarController = [[UITabBarController alloc] init];
// Must be placed here, just before tabs are added. Otherwise navigation bar
// will overlap with status bar.
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
[self addViewControllersToTabBar];
self.window.rootViewController = self.tabBarController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void)addViewControllersToTabBar
{
NSArray* tabBarClassNames =
#[
NSStringFromClass([FirstViewController class]),
NSStringFromClass([SecondViewController class]),
NSStringFromClass([FirstViewController class]),
NSStringFromClass([FirstViewController class]),
NSStringFromClass([FirstViewController class]),
NSStringFromClass([SecondViewController class]),
NSStringFromClass([FirstViewController class]),
];
NSMutableArray* viewControllers = [NSMutableArray array];
for (NSString* className in tabBarClassNames)
{
UIViewController* viewController = [[NSClassFromString(className) alloc] init];
UINavigationController* navigationController;
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewControllers addObject:navigationController];
}
[viewControllers addObject:[[FirstViewController alloc] init]]; // This one is fine.
self.tabBarController.viewControllers = viewControllers;
self.tabBarController.selectedViewController = viewControllers[2];
}
and the view controllers are literally nothing more than:
#implementation SecondViewController
- (instancetype)init
{
if (self = [super init])
{
self.title = #"second";
self.tabBarItem.image = [UIImage imageNamed:#"second.png"];
}
return self;
}
#end
Holy shit, spent so much time on this bug, but here's my workaround. Instead of:
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
I created my own NavigationController as subclass of UINavigationController:
#implementation NavigationController
- (instancetype)initWithRootViewController:(UIViewController*)rootViewController
{
if (self = [super initWithRootViewController:rootViewController])
{
NSString* className = NSStringFromClass([rootViewController class]);
NSString* name = [className stringByReplacingOccurrencesOfString:#"ViewController" withString:#""];
self.tabBarItem.image = [UIImage imageNamed:[NSString stringWithFormat:#"%#Tab.png", name]];
}
return self;
}
#end
and then do:
navigationController = [[NavigationController alloc] initWithRootViewController:viewController];
Prerequisite is that tab images have the same base name as the view controller class name, which was already the case in my app.
I was setting self.tabBarItem.image inside the view controllers' init method, and this seems to cause the effect I was seeing. So in addition to using my own navigation controller, I also simply deleted setting the tabBarItem in each individual view controller.
I have a class (ViewOpenAppointments) where I create and display a UIPopover. This is the code to define the popover in my .h file:
#interface ViewOpenAppointments : UIView {
}
#property (nonatomic, retain) UIPopoverController *popoverController;
-(void)createOpenAppointmentsPopover: (UIButton *) obViewOpenAppts;
#end
I have a check in the code that if the popover is visible, dismiss it. This is the code:
// create popover
UIViewController* popoverContent = [[UIViewController alloc] init];
// UIView *popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 650, 416)];
ViewOpenAppointments *popoverView = [[ViewOpenAppointments alloc] initWithFrame:CGRectMake(0, 0, 650, 416)];
popoverView.backgroundColor = [UIColor whiteColor];
popoverContent.preferredContentSize = CGSizeMake(650.0, 416.0);
// create the popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate = (id)self;
[popoverController setPopoverContentSize:CGSizeMake(650, 416) animated:NO];
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
}
[popoverController presentPopoverFromRect:CGRectMake(650, 416, 10, 50) inView: obViewOpenAppts
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
The problem is that the code to dismiss the popover is never hit, which means it's not visible. But I still get the error message (described in the question title).
What am I doing wrong?
Here is a complete popover management example:
#interface ViewController () <UIPopoverControllerDelegate>
#property (nonatomic, strong) UIPopoverController* currentPop;
#end
#implementation ViewController
-(IBAction)doPopover1:(id)sender {
Popover1View1* vc = [[Popover1View1 alloc] initWithNibName:#"Popover1View1" bundle:nil];
UIPopoverController* pop = [[UIPopoverController alloc] initWithContentViewController:vc];
self.currentPop = pop;
[pop presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
pop.passthroughViews = nil;
// make ourselves delegate so we learn when popover is dismissed
pop.delegate = self;
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)pc {
self.currentPop = nil;
}
By checking self.currentPop you can make sure you don't present two popovers at once (illegal anyway).
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
FirstViewController *fvc = [[FirstViewController alloc] init];
SecondtViewController *svc = [[FirstViewController alloc] init];
//Create UITabBarController
UITabBarController *theTabBarController = [[UITabBarController alloc] init];
NSArray *viewControllers = [NSSArry arrayWithObjects: fvc, svc, nil];
[theTabBarController setViewControllers:viewControllers];
// Create UINavigationController
UINavigationController *theNavigationController = [[UINavigationController
alloc]initWithRootViewController:theTabBarController];
[[self window] setRootViewController:theNavigationController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Then in the First View Controller i do a push to a second view
- (IBAction)Page2:(id)sender {
SBHomePageDetailViewController *detailPageViewController = [[SBHomePageDetailViewController alloc] init];
// Pushing to the stack
[[self navigationController] pushViewController:detailPageViewController animated:YES];
}
Now my UI shows the second view, however, the UITabBarController is missing. When i navigate back the tab bar view is back. How do I keep the tab bar controller visible in all ui screens?
Into AppDelegate.h file make property of theTabBarController:
#property (nonatomic, strong) UITabBarController *theTabBarController;
And here how I changed your didFinishLaunchingWithOptions method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
FirstViewController *fvc = [[FirstViewController alloc] init];
SecondtViewController *svc = [[SecondtViewController alloc] init];
// Create UINavigationController
UINavigationController *theNavigationController = [[UINavigationController
alloc]initWithRootViewController:fvc];
//Create UITabBarController
self.theTabBarController = [[UITabBarController alloc] init];
NSArray *viewControllers = [NSArray arrayWithObjects: theNavigationController, svc, nil];
[self.theTabBarController setViewControllers:viewControllers];
[[self window] setRootViewController:theNavigationController];
[[self window] addSubview:self.theTabBarController.view];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
The problem in the code is that it tries to initialize a UITabBarController as the rootViewController of a UINavigationController in this line:
// Create UINavigationController
UINavigationController *theNavigationController = [[UINavigationController alloc]initWithRootViewController:theTabBarController];
From the docs:
rootViewController:
The view controller that resides at the bottom of the navigation stack. This object cannot be an instance of the UITabBarController class.
Try removing that line and, per #rmaddy's suggestion, put each View Controller in a Navigation Controller. Then set those Navigation Controllers as the Tab Bar Controller's VCs and set the App's RootViewController to the Tab Bar Controller:
FirstViewController *fvc = [[FirstViewController alloc] init];
SecondtViewController *svc = [[SecondtViewController alloc] init];
// Create the first UINavigationController
UINavigationController *firstNavigationController = [[UINavigationController
alloc]initWithRootViewController:fvc];
// Create the second UINavigationController
UINavigationController *secondNavigationController = [[UINavigationController
alloc]initWithRootViewController:svc];
//Create UITabBarController
theTabBarController = [[UITabBarController alloc] init];
NSArray *viewControllers = [NSArray arrayWithObjects: firstNavigationController, secondNavigationController, nil];
[theTabBarController setViewControllers:viewControllers];
[[self window] setRootViewController: theTabBarController];
Please, help to understand the navigation. I'm working with xibs. The scheme is: https://www.dropbox.com/s/o82fxpte0hmyxcq/Scheme_Simple.jpg .
Here's my code :
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
FirstViewController *firstViewController = [[firstViewController alloc] initWithNibName:#"firstViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
#implementation FirstViewController
- (IBAction)button1Tapped:(id)sender {
SecondViewController *secondViewController = [[SecondViewController alloc] init];
secondViewController.title = #"View2";
[self.navigationController pushViewController:secondViewController animated:YES];
}
#implementation SecondViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ThirdViewController *thirdViewController = [[ThirdViewController alloc] init];
thirdViewController.title = #"View3";
if (indexPath.row == 0) {
[self.navigationController pushViewController:thirdViewController animated:YES];
[secondViewTableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
So, I have questions:
Where should I create the next view? In my code view has created in "previous" class: view2 created in FirstViewController, view3 created in SecondViewController etc. All new ViewControllers are inside the method that initiates the navigation, is it right way? I think it's wrong, but the navigation is working.
Problems with headers in the navigation bar. It turns out that the title of view2 is only displayed when moving from view1 to view2, but when going back from view3 to view2 – header disappears. I googled, tried to add self.title = #"name" to viewDidLoad, initWithNibName, viewWillAppear – none of this works.
So I've solved the problem with disappearing title of navigation bar. The problem was in my custom back button: self.navigationItem.title = #"";
It was working and title "Back" from my back button disappeared but also title of navigation bar disappeared too. The right way to make back button untitled is:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStyleBordered target:nil action:nil];
[self.navigationItem setBackBarButtonItem:backButton];
i'm working in ios application i need to customize tabbar to be like this
First I created 5 viewcontrollers each one in navigation controller
then put them in tabbbarcontroller
I googled for this problem and I found solution
[self.tabBarItem setFinishedSelectedImage:<#(UIImage *)#> withFinishedUnselectedImage:<#(UIImage *)#>]
but it is for iOS 5, I need solution for both iOS 4 and iOS 5.
For customizing tab bar in ios4 is not available with code for that you need to make us custom tab bar for that you can refer this Que.
How to Customize the tabbarcontroller
or you also can do like simple logic with making full tab bar image like this
here i have made one image view on appdel did finish method and done like this in the app.
self.imgV.frame=CGRectMake(0, 431, 320, 49);
[self.tabbarcontroller.view addSubview:self.imgV];
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
NSUInteger index=[[tabBarController viewControllers] indexOfObject:viewController];
NSString *deviceType = [UIDevice currentDevice].model;
NSLog(#"Device%#",deviceType);
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad){
// self.imgV.frame=CGRectMake(0, 975, 768, 49);
//[self.tabbarcontroller.view addSubview:self.imgV];
switch (index) {
case 0:
self.imgV.image=[UIImage imageNamed:#"reservation_tab~iPad.png"];
break;
case 1:
self.imgV.image=[UIImage imageNamed:#"place_order_tab~iPad.png"];
break;
case 2:
self.imgV.image=[UIImage imageNamed:#"location_tab~iPad.png"];
break;
case 3:
self.imgV.image=[UIImage imageNamed:#"favorite_tab~iPad.png"];
break;
case 4:
self.imgV.image=[UIImage imageNamed:#"signature_dishes_tab~iPad.png"];
break;
case 5:
self.imgV.image=[UIImage imageNamed:#"history_tab~iPad.png"];
break;
case 6:
self.imgV.image=[UIImage imageNamed:#"contact_us_tab~iPad.png"];
break;
default:
break;
}
}
else{
switch (index) {
case 0:
self.imgV.image=[UIImage imageNamed:#"reservation_tab.png"];
break;
case 1:
self.imgV.image=[UIImage imageNamed:#"place_order_tab.png"];
break;
case 2:
self.imgV.image=[UIImage imageNamed:#"location_tab.png"];
break;
case 3:
self.imgV.image=[UIImage imageNamed:#"favorite_tab.png"];
break;
case 4:
self.imgV.image=[UIImage imageNamed:#"gallery_tab.png"];
break;
default:
break;
}
}
return YES;
}
In the AppDelegate.m file, add the following code. In that piece of code, we are creating four views and adding them to a Tab Controller. These views are empty for now because we don’t need any content in them for the purposes of this project.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITabBarController *tabController = [[UITabBarController alloc] init];
UIViewController *viewController1 = [[UIViewController alloc] init];
UIViewController *viewController2 = [[UIViewController alloc] init];
UIViewController *viewController3 = [[UIViewController alloc] init];
UIViewController *viewController4 = [[UIViewController alloc] init];
tabController.viewControllers = [NSArray arrayWithObjects:viewController1,
viewController2,
viewController3,
viewController4, nil];
self.window.rootViewController = tabController;
[self.window makeKeyAndVisible];
return YES;
}
You can see a good tutorial here
try this
paste it .h file
#import <UIKit/UIKit.h>
#class MapViewController,MenuViewController;
#interface UITabBar (ColorExtensions)
- (void)recolorItemsWithColor:(UIColor *)color shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur;
#end
#interface UITabBarItem (Private)
#property(retain, nonatomic) UIImage *selectedImage;
- (void)_updateView;
#end
#interface SegmentedControlExampleAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow * window;
UINavigationController * navigationController;
NSMutableArray *breads;
NSMutableArray *categorys;
NSMutableArray *collections;
NSString *databaseName;
NSString *databasePath;
MapViewController *mapViewController;
MenuViewController *wvTutorial;
}
#property (nonatomic, retain) IBOutlet UIWindow * window;
#property (nonatomic, retain) UINavigationController * navigationController;
#property (nonatomic,retain) NSMutableArray *breads;
#property (nonatomic,retain) NSMutableArray *categorys;
#property (nonatomic,retain) NSMutableArray *collections;
#property (nonatomic, retain) UITabBarController *tabBarController;
#property (nonatomic, retain) MenuViewController *wvTutorial;
#end
In .m file
#import "SegmentedControlExampleAppDelegate.h"
#import "SegmentManagingViewController.h"
#import "sqlite3.h"
#import "AtoZHomePageViewController.h"
#import "CategoryViewHomePage.h"
#import "CollectionsListHomePageViewController.h"
#import "AboutUs.h"
#import "StoreLocatorViewController.h"
#import "UINavigationBar+CustomImage.h"
#import "MenuViewController.h"
#implementation UITabBar (ColorExtensions)
- (void)recolorItemsWithColor:(UIColor *)color shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur
{
CGColorRef cgColor = [color CGColor];
CGColorRef cgShadowColor = [shadowColor CGColor];
for (UITabBarItem *item in [self items])
if ([item respondsToSelector:#selector(selectedImage)] &&
[item respondsToSelector:#selector(setSelectedImage:)] &&
[item respondsToSelector:#selector(_updateView)])
{
CGRect contextRect;
contextRect.origin.x = 0.0f;
contextRect.origin.y = 0.0f;
contextRect.size = [[item selectedImage] size];
// Retrieve source image and begin image context
UIImage *itemImage = [item image];
CGSize itemImageSize = [itemImage size];
CGPoint itemImagePosition;
itemImagePosition.x = ceilf((contextRect.size.width - itemImageSize.width) / 2);
itemImagePosition.y = ceilf((contextRect.size.height - itemImageSize.height) / 2);
UIGraphicsBeginImageContext(contextRect.size);
CGContextRef c = UIGraphicsGetCurrentContext();
// Setup shadow
CGContextSetShadowWithColor(c, shadowOffset, shadowBlur, cgShadowColor);
// Setup transparency layer and clip to mask
CGContextBeginTransparencyLayer(c, NULL);
CGContextScaleCTM(c, 1.0, -1.0);
CGContextClipToMask(c, CGRectMake(itemImagePosition.x, -itemImagePosition.y, itemImageSize.width, -itemImageSize.height), [itemImage CGImage]);
// Fill and end the transparency layer
CGContextSetFillColorWithColor(c, cgColor);
contextRect.size.height = -contextRect.size.height;
CGContextFillRect(c, contextRect);
CGContextEndTransparencyLayer(c);
// Set selected image and end context
[item setSelectedImage:UIGraphicsGetImageFromCurrentImageContext()];
UIGraphicsEndImageContext();
// Update the view
[item _updateView];
}
}
#end
#implementation SegmentedControlExampleAppDelegate
#synthesize window,tabBarController, navigationController,breads,categorys,collections,wvTutorial;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
databaseName = #"ProductsConnect_Master.sqlite";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
self.tabBarController = [[UITabBarController alloc] init];
UIViewController *viewController = [[AboutUs alloc] initWithNibName:#"AboutUs" bundle:nil];
UIViewController *viewController2 = [[StoreLocatorViewController alloc] initWithNibName:#"StoreLocatorViewController" bundle:nil];
//UIViewController *viewController3 = [[MenuViewController alloc] initWithNibName:#"MenuViewController" bundle:nil];
self.wvTutorial = [[MenuViewController alloc]initWithNibName:#"MenuViewController" bundle:nil];
SegmentManagingViewController * segmentManagingViewController = [[SegmentManagingViewController alloc] init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:segmentManagingViewController];
tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController,viewController ,viewController2,wvTutorial , nil];
[[UITabBar appearance]
setTintColor: [UIColor colorWithRed:120.0f/255.0f green:69.0f/255.0f blue:50.0f/255.0f alpha:1.0f]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:255.0f/255.0f green:252.0f/255.0f blue:235.0f/255.0f alpha:1.0f]];
//[[UITabBar appearance]
// setBackgroundColor: [UIColor colorWithRed:255.0f/255.0f green:252.0f/255.0f blue:235.0f/255.0f alpha:0.8f]];
navigationController.title = NSLocalizedString(#"HomePage", #"HomePage");
navigationController.tabBarItem.image = [UIImage imageNamed:#"logoSmall"];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
UIImage *navImage = [UIImage imageNamed:#"logoSmall.png"];
// self.navigationItem.setImage: navImage;
[[navigationController navigationBar] performSelectorInBackground:#selector(setBackgroundImage:) withObject:navImage];
// UIImage *navImage = [UIImage imageNamed:#"logoSmall.png"];
//[[navigationController navigationBar] performSelectorInBackground:#selector(setBackgroundImage:) withObject:navImage];
[self.window addSubview:tabBarController.view];
[segmentManagingViewController release];
//[window addSubview:self.navigationController.view];
[window makeKeyAndVisible];
return YES;
}
i have used this code working fine for me.