NavigationBarの簡単な設定

12653 ワード

http://blog.csdn.net/hufeng825/article/details/7643532#)



 



1.Label    



    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];



    titleLabel.backgroundColor = [UIColor clearColor];//  Label    



    titleLabel.font = [UIFont boldSystemFontOfSize:20];



    titleLabel.textColor = [UIColor colorWithRed:0.0/255.0 green:255.0/255.0 blue:0.0/255.0 alpha:1];



    titleLabel.textAlignment = UITextAlignmentCenter;



    titleLabel.text = @"     ";



 



2.button    



    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];



    [button setTitle:@"Button" forState:UIControlStateNormal];



    [button sizeToFit];



 



3. navigationItem   Label



   self.navigationItem.titleView = self.titleLabel;



 



4.    UIBarButtonItem       :



[UIBarButtonItem alloc]initWithTitle:(NSString *) style:(UIBarButtonItemStyle) target:(id) action:(SEL)



[UIBarButtonItem alloc]initWithBarButtonSystemItem:(UIBarButtonSystemItem) target:(id) action:(SEL)



 



 



http://blog.csdn.net/hufeng825/article/details/7643532#)



 



1.Label    



    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];



    titleLabel.backgroundColor = [UIColor clearColor];//  Label    



    titleLabel.font = [UIFont boldSystemFontOfSize:20];



    titleLabel.textColor = [UIColor colorWithRed:0.0/255.0 green:255.0/255.0 blue:0.0/255.0 alpha:1];



    titleLabel.textAlignment = UITextAlignmentCenter;



    titleLabel.text = @"     ";



 



2.button    



    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];



    [button setTitle:@"Button" forState:UIControlStateNormal];



    [button sizeToFit];



 



3. navigationItem   Label



   self.navigationItem.titleView = self.titleLabel;



 



4.    UIBarButtonItem       :



[UIBarButtonItem alloc]initWithTitle:(NSString *) style:(UIBarButtonItemStyle) target:(id) action:(SEL)



[UIBarButtonItem alloc]initWithBarButtonSystemItem:(UIBarButtonSystemItem) target:(id) action:(SEL)



 



 
 
 <wbr>NavigationBar的简单设置 <wbr>
 5. navigationItem        



    button, buttons  array,  rightBarButtonItems(   s) = array。



    UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil];



    



    UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:nil];



    



    UIBarButtonItem *button3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:nil];



    



    UIBarButtonItem *button4 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:nil];



    



    NSArray *array = [[NSArray alloc] initWithObjects:button1,button2,button3,button4, nil];



    self.navigationItem.rightBarButtonItems = array;



 



6.  NavigationBar    



self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:218/255 green:222/255 blue:250/255 alpha:1];



    



7.  NavigationBar    



    UIImage *title_bg = [UIImage imageNamed:@"title_bg"]; //    



    CGSize titleSize = self.navigationController.navigationBar.bounds.size; //  NavigationBar      



    title_bg = [self scaleToSize: title_bg size:titleSize];



    //       NavigationBar  



    [self.navigationController.navigationBar setBackgroundImage:title_bg forBarMetrics:UIBarMetricsDefault];



    //    



 



//           



-(UIImage *) scaleToSize: (UIImage *) img size:(CGSize) size{



    UIGraphicsBeginImageContext(size);



    [img drawInRect:CGRectMake(0, 0, size.width, size.height)];



    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();



    UIGraphicsEndImageContext();



    return scaledImage;



}



 



 



5. navigationItem        



    button, buttons  array,  rightBarButtonItems(   s) = array。



    UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil];



    



    UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:nil];



    



    UIBarButtonItem *button3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:nil];



    



    UIBarButtonItem *button4 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:nil];



    



    NSArray *array = [[NSArray alloc] initWithObjects:button1,button2,button3,button4, nil];



    self.navigationItem.rightBarButtonItems = array;



 



6.  NavigationBar    



self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:218/255 green:222/255 blue:250/255 alpha:1];



    



7.  NavigationBar    



    UIImage *title_bg = [UIImage imageNamed:@"title_bg"]; //    



    CGSize titleSize = self.navigationController.navigationBar.bounds.size; //  NavigationBar      



    title_bg = [self scaleToSize: title_bg size:titleSize];



    //       NavigationBar  



    [self.navigationController.navigationBar setBackgroundImage:title_bg forBarMetrics:UIBarMetricsDefault];



    //    



 



//           



-(UIImage *) scaleToSize: (UIImage *) img size:(CGSize) size{



    UIGraphicsBeginImageContext(size);



    [img drawInRect:CGRectMake(0, 0, size.width, size.height)];



    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();



    UIGraphicsEndImageContext();



    return scaledImage;



}