zoukankan      html  css  js  c++  java
  • 设置UINavigation的背景图片和背景颜色

    //通过背景图片来设置背景
    float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
    UIImage *backgroundImage = [UIImage imageNamed:@"navbg.png"];  //获取图片
    
    if(systemVersion>=5.0)
    {
        CGSize titleSize = self.navigationController.navigationBar.bounds.size;  //获取Navigation Bar的位置和大小
        backgroundImage = [self scaleToSize:backgroundImage size:titleSize];//设置图片的大小与Navigation Bar相同
        [self.navigationController.navigationBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];  //设置背景
    }
    else
    {
        [self.navigationController.navigationBar insertSubview:[[[UIImageView alloc] initWithImage:backgroundImage] autorelease] atIndex:1];
    }
    
    //调整图片大小
    - (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
        UIGraphicsBeginImageContext(size);
        [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
        UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return scaledImage;
    }
    
    //设置背景样式可用通过设置tintColor来设置
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:50/255.0 green:138/255.0 blue:233/255.0 alpha:1.0];//改变navigation的背景颜色
    
  • 相关阅读:
    sublime text 2安装Emment插件
    PHPExcel IE导出乱码问题
    还是PHPExcel问题
    一条SQL语句查询两表中两个字段
    PHPExcel导出插入图片和居中问题
    jqgrid demo
    openstack horizon 学习(1) 总览
    Python学习笔记
    微软2016校园招聘在线笔试 [Recruitment]
    动态树学习(留坑)
  • 原文地址:https://www.cnblogs.com/wanyakun/p/3403350.html
Copyright © 2011-2022 走看看