Wednesday, January 20, 2010

Adding custom view in Navigation Bar

For my example I used label, you can use any view.

CGRect labelFrame = CGRectMake( 0, 0, 100, 20);
UILabel *aLabel = [[UILabel alloc] initWithFrame:labelFrame];
aLabel.font = [UIFont systemFontOfSize:13];

aLabel.textColor = [UIColor colorWithRed:0.22 green:0.0 blue:0.0 alpha:2.0];
aLabel.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
aLabel.textAlignment = UITextAlignmentRight;

aLabel.text = @"Custom";
//Important lines
UIBarButtonItem *aLabelItem = [[UIBarButtonItem alloc] initWithCustomView:aLabel];
self.navigationItem.rightBarButtonItem = aLabelItem;
//dont forget to release lable
[aLabel release];

Monday, January 18, 2010

Setting background color of UIView as of TableView

Setting the background color of UIView to background color used for table view by iPhone OS is pretty east . Just put the following line of code in your viewController's viewDidLoad or any UI initialization method.


self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];


And here you go...


Wish You All Belated Happy New Year....