zoukankan      html  css  js  c++  java
  • UIAppearance

    有时侯你并不想把导航条左侧按钮外观字体或背景全部用以下代码来更改

    UIBarButtonItem *rightItem = [YBarButtonItem barButtonWithStyle:YBarButtonStyleRoundedRectangle  Title:@"Save"  
                                                              Action:@selector(saveButtonClicked)  Delegate:self];  
    self.navigationItem.leftBarButtonItem = rightItem;   
    这里就有个方法可以进行全局或局部的修改:
    iOS5提供了一个比较强大的工具UIAppearance,可以轻松的统一你的界面,它提供如下两个方法:
    + (id)appearance
    + (id)appearanceWhenContainedIn:(Class <>)ContainerClass,...
    第一个方法是统一全部改,比如你设置UINavBar的tintColor,你可以这样写:[[UINavigationBar appearance] setTintColor:myColor];
    第二个方法是当出现在某个类的出现时候才会改变:例如:
    [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], [UIPopoverController class], nil] setTintColor:myPopoverNavBarColor];
     
    1.修改背景: 
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:leftButton  forState:0  barMetrics:UIBarMetricsDefault];  
     
    2.修改字体,阴影,字体颜色
    NSDictionary* textAttributes = [NSDictionary dictionaryWithObjectsAndKeys:  
                                       BAR_BUTTON_TITLE_TEXT_COLOR,UITextAttributeTextColor,  
                                       BAR_BUTTON_TITLE_FONT,UITextAttributeFont,  
                                       BAR_BUTTON_TITLE_SHADOW_COLOR,UITextAttributeTextShadowColor,  
                                       [NSValue valueWithCGSize:CGSizeMake(1, 1)],UITextAttributeTextShadowOffset,  
                                       nil];  (现在的版本都改成了NSTextAttribute.......了)
       [[UIBarButtonItem appearance] setTitleTextAttributes:textAttributes forState:0];  
     
    3,修改UIBarButtonItem中文字的位置:
     
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(2, -1)   forBarMetrics:UIBarMetricsDefault];
  • 相关阅读:
    Web开发较好用的几个chrome插件
    SQL注入专题
    内存泄露检测之ccmalloc
    ruby method lambda block proc 联系与区别 next break return
    c++构造函数详解
    VIM使用系列之一—配置VIM下编程和代码阅读环境
    一个项目经理的经验总结
    如何改正拖拉的习惯
    PHP开源软件《个人管理系统》希望大家一起来开发
    PHP 开源软件《个人管理系统》——完善登录模块
  • 原文地址:https://www.cnblogs.com/LE-Quan/p/5170297.html
Copyright © 2011-2022 走看看