zoukankan      html  css  js  c++  java
  • NavigationBar的简单设置

    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;
    
    }
  • 相关阅读:
    让a标签点击后不发生跳转
    关于antlr.collections.AST.getLine()I错误及解决
    Python -pycharm光标变粗解决办法!!
    通过了博客园的申请,感觉自己有了归宿!
    作为甲方对软件公司的项目实施团队提的几点要求
    高性能MySql学习笔记-第五章:创建高性能的索引
    高性能MySql学习笔记-第四章:Schema 与数据类型优化
    高性能MySql学习笔记-第三章:服务器性能剖析
    npm publish报错403 Forbidden
    父子组件利用@Input和@Output传值时显示undefined
  • 原文地址:https://www.cnblogs.com/shirley-1019/p/3493905.html
Copyright © 2011-2022 走看看