IT tutorials
 
Mobile
 

iPhone Developer : Working with View Controllers - Tab Bars

12/18/2012 5:57:51 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

The UITabBarController class allows users to move between multiple view controllers and to customize the bar at the bottom of the screen. This is best seen in the YouTube and iPod applications. Both offer one-tap access to different views, and both offer a More button leading to user selection and editing of the bottom bar.

With tab bars, you don’t push views the way you do with navigation bars. Instead, you assemble a collection of controllers (they can individually be UIViewControllers, UINavigationControllers, or any other kind of view controllers) and add them into a tab bar by setting the bar’s viewControllers property. It really is that simple. Cocoa Touch does all the rest of the work for you. Set allowsCustomizing to YES to enable user reordering of the bar.

Recipe 1 creates 11 simple view controllers of the BrightnessController class. This class uses a UIView embedded into mainview.xib and sets its background to a specified gray level, in this case from 0% to 100% in steps of 10%. Figure 1 (left) shows the interface in its default mode, with the first four items and a More button displayed.

Figure 1. Tab bar controllers allow users to pick view controllers from a bar at the bottom of the screen (left side of the figure) and to customize the bar from a list of available view controllers (right side of the figure).

Reorder these tabs by selecting the More option and then tapping Edit. This opens the Configure panel shown in Figure 1 (right). These 11 view controllers are the options a user can navigate through and select from.

Notice that this recipe adds those 11 controllers twice. The first time assigns them to the list of view controllers available to the user:

tbarController.viewControllers = controllers;

The second time specifies that the user can select from the entire list when interactively customizing the bottom tab bar:

tbarController.customizableViewControllers = controllers;

The second line is optional, the first mandatory. After setting up the view controllers, you can add all or some to the customizable list. If you don’t, you still can see the extra view controllers using the More button, but users won’t be able to include them in the main tab bar on demand.

Tab art appears inverted in color on the More screen. According to Apple, this is the expected and proper behavior. They have no plans to change this. It does provide an interesting view contrast when your 100% white swatch appears as pure black on that screen.

.

Recipe 1. Creating a Tab View Controller
@implementation BrightnessController
- (UIImage*) buildSwatch: (float) tint
{
    CGContextRef context  = [GraphicsUtilities
        newBitmapContextWithWidth:30 andHeight:30];
    [GraphicsUtilities addRoundedRect:
        CGRectMake(0.0f, 0.0f, 30.0f, 30.0f) toContext:context
        withWidth:4.0f andHeight:4.0f];
    CGFloat gray[4] = {tint, tint, tint, 1.0f};
    CGContextSetFillColor(context, gray);
    CGContextFillPath(context);

    CGImageRef myRef = CGBitmapContextCreateImage (context);
    free(CGBitmapContextGetData(context));
    CGContextRelease(context);
    UIImage *img = [UIImage imageWithCGImage:myRef];
    CFRelease(myRef);
    return img;
}

-(BrightnessController *) initWithBrightness: (int) aBrightness
{
    self = [super init];
    brightness = aBrightness;
    self.title = [NSString stringWithFormat:@"%d%%", brightness * 10];
    [self.tabBarItem initWithTitle:self.title image:[self
        buildSwatch:(((float)brightness) / 10.0f)] tag:0];
    return self;
}

- (void) loadView
{
    self.view = [[[NSBundle mainBundle] loadNibNamed:@"mainview"
        owner:self options:nil] lastObject];
    UIView *bigSwatch = [self.view viewWithTag:101];
    bigSwatch.backgroundColor = [UIColor colorWithWhite:
        (brightness / 10.0f) alpha:1.0f];
}
@end

@interface TestBedAppDelegate : NSObject <UIApplicationDelegate,
    UITabBarControllerDelegate>
@end

@implementation TestBedAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
    NSMutableArray *controllers = [NSMutableArray array];
    for (int i = 0; i <= 10; i++)
    {
        BrightnessController *bControl = [[BrightnessController alloc]
            initWithBrightness:i];
        UINavigationController *nav = [[UINavigationController alloc]
            initWithRootViewController:bControl];
        nav.navigationBar.barStyle = UIBarStyleBlackTranslucent;
        [bControl release];

        [controllers addObject:nav];
        [nav release];
    }

    // Create the toolbar and add the view controllers
    UITabBarController *tbarController = [[UITabBarController alloc]
        init];
    tbarController.viewControllers = controllers;
    tbarController.customizableViewControllers = controllers;
    tbarController.delegate = self;

    // Set up the window
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen
        mainScreen] bounds]];
    [window addSubview:tbarController.view];
    [window makeKeyAndVisible];
}
@end					
 
Others
 
- iPhone Developer : Working with View Controllers - Presenting a Custom Modal Information View
- Windows Phone 8 : Writing Your First Phone Application - Adding Code (part 3) - Using Touch
- Windows Phone 8 : Writing Your First Phone Application - Adding Code (part 2) - Debugging in the Emulator, Debugging with a Device
- Windows Phone 8 : Writing Your First Phone Application - Adding Code (part 1) - Working with Events
- Windows Phone 8 : Designing with Blend
- Iphone Application : Implementing Location Services - Creating a Location-Aware Application (part 2) - Implementing the Location Manager Delegate
- Iphone Application : Implementing Location Services - Creating a Location-Aware Application (part 1)
- Iphone Application : Implementing Location Services - Understanding Core Location
- Windows Phone 8 : Creating a New Project (part 2) - XAML
- Windows Phone 8 : Creating a New Project (part 1) - Visual Studio
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us