Showing posts with label UIToolbar example. Show all posts
Showing posts with label UIToolbar example. Show all posts

Tuesday, June 11, 2013

UIToolbar UIToolbarPositionTop example in Objective C (iOS).

UIToolbar UIToolbarPositionTop

UIToolbarPosition
Constants to identify the position of a toolbar for appearance customization (see setBackgroundImage:forToolbarPosition:barMetrics:).

typedef enum {
UIToolbarPositionAny = 0,
UIToolbarPositionBottom = 1,
UIToolbarPositionTop = 2,
} UIToolbarPosition;

Constants
UIToolbarPositionAny
Indicates the toolbar may be in any position.
UIToolbarPositionBottom
Indicates the toolbar is at the top of its containing view.
UIToolbarPositionTop
Indicates the toolbar is at the bottom of its containing view.

UIToolbar UIToolbarPositionTop example.
[[UIToolbar appearance] setBackgroundImage:<myImage_1> forToolbarPosition:UIToolbarPositionTop barMetrics:UIBarMetricsDefault];
could be made to work by adding

//Connect this to your toolbar in Interface Builder
@property (weak, nonatomic) IBOutlet UIToolbar *tref;
to your header. Then just do

 [tref setBackgroundImage:<myImage_1> forToolbarPosition:UIToolbarPositionTop barMetrics:UIBarMetricsDefault];

Example of [UIToolbar UIToolbarPositionTop].
  [tool setBackgroundImage:barImage forToolbarPosition:UIToolbarPositionTop
                  barMetrics:UIBarMetricsDefault];

End of UIToolbar UIToolbarPositionTop example article.

UIToolbar UIToolbarPositionBottom example in Objective C (iOS).

UIToolbar UIToolbarPositionBottom

UIToolbarPosition
Constants to identify the position of a toolbar for appearance customization (see setBackgroundImage:forToolbarPosition:barMetrics:).

typedef enum {
UIToolbarPositionAny = 0,
UIToolbarPositionBottom = 1,
UIToolbarPositionTop = 2,
} UIToolbarPosition;

Constants
UIToolbarPositionAny
Indicates the toolbar may be in any position.
UIToolbarPositionBottom
Indicates the toolbar is at the top of its containing view.
UIToolbarPositionTop
Indicates the toolbar is at the bottom of its containing view.

UIToolbar UIToolbarPositionBottom example.
By subclassing UIToolBar and overriding drawRect, you eliminate some of UIToolBar's own drawing. Why not use the appearance api to set a background image:

[[UIToolbar appearance] setBackgroundImage:[UIImage imageNamed:@"UIToolBar_Background.png"]
                        forToolbarPosition:UIToolbarPositionBottom
                                barMetrics:UIBarMetricsDefault];

Example of [UIToolbar UIToolbarPositionBottom].
[_bottomToolbar setBackgroundImage:nil
                forToolbarPosition:UIToolbarPositionBottom
                        barMetrics:UIBarMetricsDefault];
[self.view addSubview:_bottomToolbar];

UIToolbar UIToolbarPositionBottom example.
UIImage *barImage=[[UIImage imageNamed:@"BarBg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(27,0,27,0)];
[tool setBackgroundImage:barImage forToolbarPosition:UIToolbarPositionBottom
              barMetrics:UIBarMetricsDefault];
 [self.view addSubview:tool];

End of UIToolbar UIToolbarPositionBottom example article.

UIToolbar UIToolbarPositionAny example in Objective C (iOS).

UIToolbar UIToolbarPositionAny

UIToolbarPosition
Constants to identify the position of a toolbar for appearance customization (see setBackgroundImage:forToolbarPosition:barMetrics:).

typedef enum {
UIToolbarPositionAny = 0,
UIToolbarPositionBottom = 1,
UIToolbarPositionTop = 2,
} UIToolbarPosition;

Constants
UIToolbarPositionAny
Indicates the toolbar may be in any position.
UIToolbarPositionBottom
Indicates the toolbar is at the top of its containing view.
UIToolbarPositionTop
Indicates the toolbar is at the bottom of its containing view.

UIToolbar UIToolbarPositionAny example.
// Setup top tool bar
UIToolbar *topToolbar = [[UIToolbar alloc] init];
[topToolbar setBackgroundImage:[UIImage imageNamed:@"top_toolbar.png"]
               forToolbarPosition:UIToolbarPositionAny
                       barMetrics:UIBarMetricsDefault];

// Setup bottom toolbar
UIToolbar *bottomToolbar = [[UIToolbar alloc] init];
[bottomToolbar setBackgroundImage:[UIImage imageNamed:@"bottom_toolbar.png"]
               forToolbarPosition:UIToolbarPositionAny
                       barMetrics:UIBarMetricsDefault];

Example of [UIToolbar UIToolbarPositionAny].
UIImage *testimage = [[UIImage imageNamed:@"bartop"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UIToolbar appearance] setBackgroundImage:testimage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
[[UIToolbar appearance] setBackgroundImage:testimage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsLandscapePhone];

UIToolbar UIToolbarPositionAny example.
UIImage *image = [UIImage imageNamed:@"myimage.png"];
[[UIToolbar appearance] setBackgroundImage:image forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
You only have to do this once to get the same appearance for all UIToolBars in your app. You can also set many of (if not all?) the properties of your UIToolBar.


End of UIToolbar UIToolbarPositionAny example article.

UIToolbar setShadowImage forToolbarPosition example in Objective C (iOS).

UIToolbar setShadowImage forToolbarPosition

Sets the image to use for the toolbar shadow in a given position.

- (void)setShadowImage:(UIImage *)shadowImage forToolbarPosition:(UIToolbarPosition)topOrBottom

Parameters of [UIToolbar setShadowImage forToolbarPosition]
shadowImage
The image to use for the toolbar shadow in the position specified by topOrBottom.
topOrBottom
A toolbar position constant. You can use this parameter to indicate whether the shadowImage is intended for a toolbar at the top or bottom of the view.

Discussion of [UIToolbar setShadowImage forToolbarPosition]
When the shadowImage parameter is nil, the default shadow will be used. When non-nil, the shadowImage property is a custom shadow image to show instead of the default. Using the topOrBottom parameter, you can set a different shadow for toolbars at the top and bottom of the view. For a custom shadow image to be shown, a custom background image must also be set with the setBackgroundImage:forToolbarPosition:barMetrics: method. If the default background image is used, then the default shadow image will be used regardless of the value of the shadowImage parameter.

UIToolbar setShadowImage forToolbarPosition example.
Add this line also

[toolbar setShadowImage:_maskedImage forToolbarPosition:UIToolbarPositionAny];
But beware this will only work in iOS6

Example of [UIToolbar setShadowImage forToolbarPosition].
- (void)setTransparent
{
    //iOS3+
    self.backgroundColor = [UIColor clearColor];

    //iOS5+
    if ([self respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)])
    {
        [self setBackgroundImage:[[UIImage new] autorelease] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
    }
    //iOS6+
    if ([self respondsToSelector:@selector(setShadowImage:forToolbarPosition:)])
    {
        [self setShadowImage:[[UIImage new] autorelease] forToolbarPosition:UIToolbarPositionAny];
    }
}

End of UIToolbar setShadowImage forToolbarPosition example article.

UIToolbar setShadowImage example in Objective C (iOS).

UIToolbar setShadowImage

Sets the image to use for the toolbar shadow in a given position.

- (void)setShadowImage:(UIImage *)shadowImage forToolbarPosition:(UIToolbarPosition)topOrBottom

Parameters of [UIToolbar setShadowImage]
shadowImage
The image to use for the toolbar shadow in the position specified by topOrBottom.
topOrBottom
A toolbar position constant. You can use this parameter to indicate whether the shadowImage is intended for a toolbar at the top or bottom of the view.

Discussion of [UIToolbar setShadowImage]
When the shadowImage parameter is nil, the default shadow will be used. When non-nil, the shadowImage property is a custom shadow image to show instead of the default. Using the topOrBottom parameter, you can set a different shadow for toolbars at the top and bottom of the view. For a custom shadow image to be shown, a custom background image must also be set with the setBackgroundImage:forToolbarPosition:barMetrics: method. If the default background image is used, then the default shadow image will be used regardless of the value of the shadowImage parameter.

UIToolbar setShadowImage example.
Add this line also

[toolbar setShadowImage:_maskedImage forToolbarPosition:UIToolbarPositionAny];
But beware this will only work in iOS6

Example of [UIToolbar setShadowImage].
- (void)setTransparent
{
    //iOS3+
    self.backgroundColor = [UIColor clearColor];

    //iOS5+
    if ([self respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)])
    {
        [self setBackgroundImage:[[UIImage new] autorelease] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
    }
    //iOS6+
    if ([self respondsToSelector:@selector(setShadowImage:forToolbarPosition:)])
    {
        [self setShadowImage:[[UIImage new] autorelease] forToolbarPosition:UIToolbarPositionAny];
    }
}

End of UIToolbar setShadowImage example article.

UIToolbar setItems animated example in Objective C (iOS).

UIToolbar setItems animated

Sets the items on the toolbar by animating the changes.

- (void)setItems:(NSArray *)items animated:(BOOL)animated

Parameters of [UIToolbar setItems animated]
items
The items to display on the toolbar.
animated
A Boolean value if set to YES animates the transition to the items; otherwise, does not.

Discussion of [UIToolbar setItems animated]
If animated is YES, the changes are dissolved or the reordering is animated—for example, removed items fade out and new items fade in. This method also adjusts the spacing between items.

UIToolbar setItems animated example.
NSMutableArray *items = [[self.toolbar items] mutableCopy];

UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[items addObject:spacer];
[spacer release];

self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0 , 11.0f, self.view.frame.size.width, 21.0f)];
[self.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
[self.titleLabel setBackgroundColor:[UIColor clearColor]];
[self.titleLabel setTextColor:[UIColor colorWithRed:157.0/255.0 green:157.0/255.0 blue:157.0/255.0 alpha:1.0]];
[self.titleLabel setText:@"Title"];
[self.titleLabel setTextAlignment:UITextAlignmentCenter];

UIBarButtonItem *spacer2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[items addObject:spacer2];
[spacer2 release];

UIBarButtonItem *title = [[UIBarButtonItem alloc] initWithCustomView:self.titleLabel];
[items addObject:title];
[title release];

[self.toolbar setItems:items animated:YES];
[items release];

Example of [UIToolbar setItems animated].
- (void)viewDidLoad {
[super viewDidLoad];// Add an invisible UIActivityViewIndicator to the toolbar
UIToolbar *toolbar = (UIToolbar *)[self.view viewWithTag:767];
NSArray *items = [toolbar items];

activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 20.0f, 20.0f)];
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];

NSArray *newItems = [NSArray arrayWithObjects:[items objectAtIndex:0],[items objectAtIndex:1],[items objectAtIndex:2],
 [[UIBarButtonItem alloc] initWithCustomView:activityIndicator], [items objectAtIndex:3],nil];
[toolbar setItems:newItems];}

UIToolbar setItems animated example.
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0, 0, self.view.frame.size.width, 45);
NSMutableArray *items = [[NSMutableArray alloc] init];
[items addObject:[[UIBarButtonItem alloc] initWithObjects...]];
[toolbar setItems:items animated:NO];
[self.view addSubview:toolbar];

End of UIToolbar setItems animated example article.

UIToolbar setItems example in Objective C (iOS).

UIToolbar setItems

Sets the items on the toolbar by animating the changes.

- (void)setItems:(NSArray *)items animated:(BOOL)animated

Parameters of [UIToolbar setItems]
items
The items to display on the toolbar.
animated
A Boolean value if set to YES animates the transition to the items; otherwise, does not.

Discussion of [UIToolbar setItems]
If animated is YES, the changes are dissolved or the reordering is animated—for example, removed items fade out and new items fade in. This method also adjusts the spacing between items.

UIToolbar setItems example.
NSMutableArray *items = [[self.toolbar items] mutableCopy];

UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[items addObject:spacer];
[spacer release];

self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0 , 11.0f, self.view.frame.size.width, 21.0f)];
[self.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
[self.titleLabel setBackgroundColor:[UIColor clearColor]];
[self.titleLabel setTextColor:[UIColor colorWithRed:157.0/255.0 green:157.0/255.0 blue:157.0/255.0 alpha:1.0]];
[self.titleLabel setText:@"Title"];
[self.titleLabel setTextAlignment:UITextAlignmentCenter];

UIBarButtonItem *spacer2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[items addObject:spacer2];
[spacer2 release];

UIBarButtonItem *title = [[UIBarButtonItem alloc] initWithCustomView:self.titleLabel];
[items addObject:title];
[title release];

[self.toolbar setItems:items animated:YES];
[items release];

Example of [UIToolbar setItems].
- (void)viewDidLoad {
[super viewDidLoad];// Add an invisible UIActivityViewIndicator to the toolbar
UIToolbar *toolbar = (UIToolbar *)[self.view viewWithTag:767];
NSArray *items = [toolbar items];

activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 20.0f, 20.0f)];
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];

NSArray *newItems = [NSArray arrayWithObjects:[items objectAtIndex:0],[items objectAtIndex:1],[items objectAtIndex:2],
 [[UIBarButtonItem alloc] initWithCustomView:activityIndicator], [items objectAtIndex:3],nil];
[toolbar setItems:newItems];}

UIToolbar setItems example.
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0, 0, self.view.frame.size.width, 45);
NSMutableArray *items = [[NSMutableArray alloc] init];
[items addObject:[[UIBarButtonItem alloc] initWithObjects...]];
[toolbar setItems:items animated:NO];
[self.view addSubview:toolbar];

End of UIToolbar setItems example article.

UIToolbar setBackgroundImage forToolbarPosition barMetrics example in Objective C (iOS).

UIToolbar setBackgroundImage forToolbarPosition barMetrics

Sets the image to use for the background in a given position and with given metrics.

- (void)setBackgroundImage:(UIImage *)backgroundImage forToolbarPosition:(UIToolbarPosition)topOrBottom barMetrics:(UIBarMetrics)barMetrics

Parameters of [UIToolbar setBackgroundImage forToolbarPosition barMetrics]
backgroundImage
The image to use for the toolbar background in the position specified by topOrBottom and with the metrics specified by barMetrics.
topOrBottom
A toolbar position constant.
barMetrics
A bar metrics constant.

UIToolbar setBackgroundImage forToolbarPosition barMetrics example.
if([navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
        //iOS 5 new UINavigationBar custom background
        [navigationBar setBackgroundImage:image forBarMetrics: UIBarMetricsDefault];
}
To realize this, take a look at here iOS 4.3 to iOS 5.0 API Differences and search for "UINavigationBar.h"


Example of [UIToolbar setBackgroundImage forToolbarPosition barMetrics].
//toolBar background image set based on iOS version
    [[UIDevice currentDevice] systemVersion];

    if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {

        //iOS 5
        UIImage *toolBarIMG = [UIImage imageNamed: @"toolBar_brown.png"]; 

        if ([toolBar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
            [toolBar setBackgroundImage:toolBarIMG forToolbarPosition:0 barMetrics:0];
        }

    } else {

        //iOS 4
        [toolBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"toolBar_brown.png"]] autorelease] atIndex:0];

    }

UIToolbar setBackgroundImage forToolbarPosition barMetrics example.
// Set the background image for PortraitMode
[self.toolbar setBackgroundImage:[UIImage imageNamed:@"Sample.png"]
                                   forBarMetrics:UIBarMetricsDefault];
// and For LandscapeMode
[self.toolbar setBackgroundImage:[UIImage imageNamed:@"Sample.png"]
                                   forBarMetrics:UIBarMetricsLandscapePhone];

End of UIToolbar setBackgroundImage forToolbarPosition barMetrics example article.

UIToolbar setBackgroundImage example in Objective C (iOS).

UIToolbar setBackgroundImage

Sets the image to use for the background in a given position and with given metrics.

- (void)setBackgroundImage:(UIImage *)backgroundImage forToolbarPosition:(UIToolbarPosition)topOrBottom barMetrics:(UIBarMetrics)barMetrics

Parameters of [UIToolbar setBackgroundImage]
backgroundImage
The image to use for the toolbar background in the position specified by topOrBottom and with the metrics specified by barMetrics.
topOrBottom
A toolbar position constant.
barMetrics
A bar metrics constant.

UIToolbar setBackgroundImage example.
if([navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
        //iOS 5 new UINavigationBar custom background
        [navigationBar setBackgroundImage:image forBarMetrics: UIBarMetricsDefault];
}
To realize this, take a look at here iOS 4.3 to iOS 5.0 API Differences and search for "UINavigationBar.h"


Example of [UIToolbar setBackgroundImage].
//toolBar background image set based on iOS version
    [[UIDevice currentDevice] systemVersion];

    if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {

        //iOS 5
        UIImage *toolBarIMG = [UIImage imageNamed: @"toolBar_brown.png"]; 

        if ([toolBar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
            [toolBar setBackgroundImage:toolBarIMG forToolbarPosition:0 barMetrics:0];
        }

    } else {

        //iOS 4
        [toolBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"toolBar_brown.png"]] autorelease] atIndex:0];

    }

UIToolbar setBackgroundImage example.
// Set the background image for PortraitMode
[self.toolbar setBackgroundImage:[UIImage imageNamed:@"Sample.png"]
                                   forBarMetrics:UIBarMetricsDefault];
// and For LandscapeMode
[self.toolbar setBackgroundImage:[UIImage imageNamed:@"Sample.png"]
                                   forBarMetrics:UIBarMetricsLandscapePhone];

End of UIToolbar setBackgroundImage example article.

UIToolbar setTranslucent example in Objective C (iOS).

UIToolbar setTranslucent

A Boolean value that indicates whether the toolbar is translucent (YES) or not (NO).

@property(nonatomic, assign, getter=isTranslucent) BOOL translucent

Discussion of [UIToolbar setTranslucent]
Applying translucence to a toolbar is intended primarily for landscape orientation, when you want the user to be able to view the area beneath the toolbar. The default value for this property is NO. However, if you set the toolbar style to UIBarStyleBlackTranslucent, the value for this property is always YES.

UIToolbar setTranslucent example.
The best you can do is using

[helloToolbar setBarStyle:UIBarStyleBlack];
[helloToolbar setTranslucent:YES];
This will get you a black but translucent toolbar.


Example of [UIToolbar setTranslucent].
// Set properties to make background
// translucent.
- (void) applyTranslucentBackground
{
    self.backgroundColor = [UIColor clearColor];
    self.opaque = NO;
    self.translucent = YES;
}

// Override init.
- (id) init
{
    self = [super init];
    [self applyTranslucentBackground];
    return self;
}

// Override initWithFrame.
- (id) initWithFrame:(CGRect) frame
{
    self = [super initWithFrame:frame];
    [self applyTranslucentBackground];
    return self;
}

UIToolbar setTranslucent example.
    UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];

    UIBarButtonItem* previous = [[UIBarButtonItem alloc] initWithTitle:@"Anterior" style:UIBarButtonItemStyleBordered target:self action:@selector(move:)];
    UIBarButtonItem* next = [[UIBarButtonItem alloc] initWithTitle:@"Próximo" style:UIBarButtonItemStyleBordered target:self action:@selector(move:)];
    UIBarButtonItem* space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemFlexibleSpace) target:nil action:nil];
    UIBarButtonItem* ok = [[UIBarButtonItem alloc] initWithTitle:@"Ok" style:UIBarButtonItemStyleBordered target:self action:@selector(ok:)];

    [toolbar setItems:[[NSArray alloc] initWithObjects:previous, next, space, ok, nil]];

    [toolbar setTranslucent:YES];
    [toolbar setTintColor:[UIColor blackColor]];

End of UIToolbar setTranslucent example article.

UIToolbar translucent example in Objective C (iOS).

UIToolbar translucent

A Boolean value that indicates whether the toolbar is translucent (YES) or not (NO).

@property(nonatomic, assign, getter=isTranslucent) BOOL translucent

Discussion of [UIToolbar translucent]
Applying translucence to a toolbar is intended primarily for landscape orientation, when you want the user to be able to view the area beneath the toolbar. The default value for this property is NO. However, if you set the toolbar style to UIBarStyleBlackTranslucent, the value for this property is always YES.

UIToolbar translucent example.
The best you can do is using

[helloToolbar setBarStyle:UIBarStyleBlack];
[helloToolbar setTranslucent:YES];
This will get you a black but translucent toolbar.


Example of [UIToolbar translucent].
// Set properties to make background
// translucent.
- (void) applyTranslucentBackground
{
    self.backgroundColor = [UIColor clearColor];
    self.opaque = NO;
    self.translucent = YES;
}

// Override init.
- (id) init
{
    self = [super init];
    [self applyTranslucentBackground];
    return self;
}

// Override initWithFrame.
- (id) initWithFrame:(CGRect) frame
{
    self = [super initWithFrame:frame];
    [self applyTranslucentBackground];
    return self;
}

UIToolbar translucent example.
check the following line of code

 _toolbar.barStyle = UIBarStyleBlackTranslucent;//Deprecated
EDIT

  _toolbar.barStyle = UIBarStyleBlack;
  _toolbar.translucent = YES;
check the UIInterface.h Class in UIKit.Framework


End of UIToolbar translucent example article.

UIToolbar setTintColor example in Objective C (iOS).

UIToolbar setTintColor

The color used to tint the bar.

@property(nonatomic, retain) UIColor *tintColor

Discussion of [UIToolbar setTintColor]
The default value is nil.

UIToolbar setTintColor example.
-(void)viewDidLoad{
    [super viewDidLoad];
    //Custom initialization
    [self.webControlsToolbar_ setTintColor:[UIColor colorWithRed:246.0/255.0 green:246.0/255.0 blue:246.0/255.0 alpha:1]];

}

Example of [UIToolbar setTintColor].
There no way to compare the colors of navigation bar and tool bar but you can set toolbar color with following code

    aToolbar.barStyle = UIBarStyleBlackTranslucent;
    aToolbar.tintColor = [UIColor blackColor];
    aToolbar.alpha = 0.7;
or

aToolBar.tintColor = [UIColor colorWithRed:0.15 green:0.35 blue:0.45 alpha:0.6];

UIToolbar setTintColor example.
Have a look at the setTintColor: method. For example:

[self.navigationController.toolbar setTintColor:[UIColor greenColor]];

End of UIToolbar setTintColor example article.

UIToolbar tintColor example in Objective C (iOS).

UIToolbar tintColor

The color used to tint the bar.

@property(nonatomic, retain) UIColor *tintColor

Discussion of [UIToolbar tintColor]
The default value is nil.

UIToolbar tintColor example.
UIToolbar also has a tintColor property, just like a UINavigationBar. You should be able to set one to the other:

myToolbar.tintColor = myNavBar.tintColor;
after you create your toolbar. Keep in mind that this code would only work if myNavBar had been loaded from the NIB, so it would be best to put this in viewWillAppear: or viewDidLoad.


Example of [UIToolbar tintColor].
There no way to compare the colors of navigation bar and tool bar but you can set toolbar color with following code

    aToolbar.barStyle = UIBarStyleBlackTranslucent;
    aToolbar.tintColor = [UIColor blackColor];
    aToolbar.alpha = 0.7;
or

aToolBar.tintColor = [UIColor colorWithRed:0.15 green:0.35 blue:0.45 alpha:0.6];

UIToolbar tintColor example.
// Toolbar content              
NSArray *items=[NSArray arrayWithObjects: ... ]; // PSEUDO CODE HERE
[toolbar setItems:items];

// Add tint
toolbar.tintColor = [UIColor colorWithRed:0.83 green:0.43 blue:0.57 alpha:0.5];
What I needed to do, was just reverse the order of things:

// Add tint
toolbar.tintColor = [UIColor colorWithRed:0.83 green:0.43 blue:0.57 alpha:0.5];

// Toolbar content              
NSArray *items=[NSArray arrayWithObjects: ... ]; // PSEUDO CODE HERE
[toolbar setItems:items]; 

End of UIToolbar tintColor example article.

UIToolbar items example in Objective C (iOS).

UIToolbar items

The items displayed on the toolbar.

@property(nonatomic, copy) NSArray *items

Discussion of [UIToolbar items]
The items, instances of UIBarButtonItem, that are visible on the toolbar in the order they appear in this array. Any changes to this property are not animated. Use the setItems:animated: method to animate changes.

The default value is nil.

UIToolbar items example.
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[toolbar setItems:[NSArray arrayWithObjects:flexibleSpace, settingsButton,deleteButton,aboutButton, flexibleSpace, nil]];
[flexibleSpace release];

Example of [UIToolbar items].
- (void)updateBarButtonItemChecked:(BOOL)checked {
    if (toolbarItems == nil) {
     toolbarItems = [[NSMutableArray arrayWithArray:toolbar.items] retain];
     checkUncheckIndex = -1;

     for (NSUInteger i = 0; i < [toolbarItems count]; i++) {
     UIBarButtonItem *barButtonItem = [toolbarItems objectAtIndex:i];
     if (barButtonItem.action == @selector(checkUncheckClicked)) {
     favoriteIndex = i;
     break;
     }
     }
    }

    if (checkUncheckIndex != -1) {
     UIBarButtonItem *barButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:checked ? @"checked.png" : @"unchecked.png"]
        style:UIBarButtonItemStylePlain target:self action:@selector(checkUncheckClicked)] autorelease];
     [toolbarItems replaceObjectAtIndex:checkUncheckIndex withObject:barButtonItem];

     toolbar.items = toolbarItems;
    }
}

UIToolbar items example.
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0, 0, self.view.frame.size.width, 45);
NSMutableArray *items = [[NSMutableArray alloc] init];
[items addObject:[[UIBarButtonItem alloc] initWithObjects...]];
[toolbar setItems:items animated:NO];
[self.view addSubview:toolbar];

End of UIToolbar items example article.

UIToolbar setBarStyle example in Objective C (iOS).

UIToolbar setBarStyle

The toolbar style that specifies its appearance.

@property(nonatomic) UIBarStyle barStyle

Discussion of [UIToolbar setBarStyle]
See UIBarStyle for possible values. The default value is UIBarStyleDefault.

UIToolbar setBarStyle example.
In the view controller where you want to set this, add the following to viewDidLoad:

[self.navigationController.toolbar setBarStyle:UIBarStyleBlackTranslucent];

Example of [UIToolbar setBarStyle].
self.bottomToolbar.barStyle = UIBarStyleBlack;
self.bottomToolbar.translucent = YES;
self.bottomToolbar.backgroundColor = [UIColor clearColor];
View opacity set to 1 and these settings did it for me.


UIToolbar setBarStyle example.
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[self.navigationController.toolbar setBarStyle:UIBarStyleBlackOpaque];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:@"toolbar title" style:UIBarButtonItemStylePlain    target:self     action:@selector(onToolbarTapped:)];
NSArray *toolbarItems = [NSArray arrayWithObjects:spaceItem, customItem, spaceItem, nil];

[self setToolbarItems:toolbarItems animated:NO];

End of UIToolbar setBarStyle example article.

UIToolbar barStyle example in Objective C (iOS).

UIToolbar barStyle

The toolbar style that specifies its appearance.

@property(nonatomic) UIBarStyle barStyle

Discussion of [UIToolbar barStyle]
See UIBarStyle for possible values. The default value is UIBarStyleDefault.

UIToolbar barStyle example.
In the view controller where you want to set this, add the following to viewDidLoad:

[self.navigationController.toolbar setBarStyle:UIBarStyleBlackTranslucent];

Example of [UIToolbar barStyle].
self.bottomToolbar.barStyle = UIBarStyleBlack;
self.bottomToolbar.translucent = YES;
self.bottomToolbar.backgroundColor = [UIColor clearColor];
View opacity set to 1 and these settings did it for me.


UIToolbar barStyle example.
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[self.navigationController.toolbar setBarStyle:UIBarStyleBlackOpaque];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:@"toolbar title" style:UIBarButtonItemStylePlain    target:self     action:@selector(onToolbarTapped:)];
NSArray *toolbarItems = [NSArray arrayWithObjects:spaceItem, customItem, spaceItem, nil];

[self setToolbarItems:toolbarItems animated:NO];

End of UIToolbar barStyle example article.