zoukankan      html  css  js  c++  java
  • UINavigationBar-使用总结

    多视图应用程序中,我们常常使用到自定义UINavigationBar来完成导航条的设置。
     
    1.获取导航条
     

    UINavigationBar *navBar = self.navigationController.navigationBar;

     
    2.设置导航条样式(使用系统自带样式)
     

    [navBar setBarStyle:UIBarStyleDefault];

     
    分别有如下几种样式:

    typedef NS_ENUM(NSInteger, UIBarStyle) {

        UIBarStyleDefault          = 0,

        UIBarStyleBlack            = 1,

        UIBarStyleBlackOpaque      = 1, // Deprecated. Use UIBarStyleBlack

        UIBarStyleBlackTranslucent = 2, // Deprecated. Use UIBarStyleBlack and set the translucent property to YES

    };

     
    从字面我们就能了解这4种样式的大概意思:
    分别为:
    UIBarStyleDefault:默认样式
    UINavigationBar-使用总结

    UIBarStyleBlack:黑色
    UINavigationBar-使用总结

    UIBarStyleBlackOpaque:黑色不透明
    UINavigationBar-使用总结
     
    UIBarStyleBlackTranslucent:黑色透明
    UINavigationBar-使用总结

    注意:我们发现,在后面两个标记为Deprecated,我们知道使用后面两种将不被提倡。
    从枚举中,我们也可以看出:UIBarStyleBlack=1和UIBarStyleBlackOpaque=1表示为一样的。
    后来,发现增加了一个方法:[navBar setTranslucent:YES];用来指示是否透明。
     
    所以,我们使用UIBarStyleDefault和UIBarStyleBlack来定义UINavigationBar样式,并且用setTranslucent:方法来设置透明与否。
     
    3.自定义导航条颜色
     
    如果,仅仅使用这4种(2种样式*是否透明),难免太逊了,必须能自定义UINavigationBar样式啊。
     

    if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){

            // UIBarMetricsLandscapePhone

            [navBar setBackgroundImage:[UIImage imageNamed:@"图片名称"] forBarMetrics:UIBarMetricsDefault];

        }

     

    setBackgroundImage方法的第二个参数,需要解释一下:
     
    UIBarMetricsDefault:用竖着(拿手机)时UINavigationBar的标准的尺寸来显示UINavigationBar

    UIBarMetricsLandscapePhone:用横着UINavigationBar标准尺寸来显示UINavigationBar

     
  • 相关阅读:
    hdu1087Super Jumping! Jumping! Jumping!
    hdu1159Common Subsequence(最长公共子序列)
    hdu1069Monkey and Banana(最长递增子序列)
    poj2533(最长递增子序列)
    hdu1029Ignatius and the Princess IV
    uva10622(唯一分解定理)
    myeclipse设置技巧
    myeclipse2014新感悟
    小错误汇总
    字符串反转
  • 原文地址:https://www.cnblogs.com/mawenqiangios/p/5885245.html
Copyright © 2011-2022 走看看