zoukankan      html  css  js  c++  java
  • UIAppearance

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

    [plain] 
    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.修改背景:
    [plain]  
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:leftButton  
                                                          forState:0  
                                                        barMetrics:UIBarMetricsDefault];  
     
    2.修改字体,阴影,字体颜色
    [plain]  
    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];  
      
       [[UIBarButtonItem appearance] setTitleTextAttributes:textAttributes forState:0];  
     
    3,修改UIBarButtonItem中文字的位置:
    [plain] 
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(2, -1)  
                                                           forBarMetrics:UIBarMetricsDefault];  
     
    转:http://www.2cto.com/kf/201301/186764.html
  • 相关阅读:
    django关闭调试信息,打开内置错误视图
    django 配置URLconf和获取值
    django模版中配置和使用静态文件方法
    django的模型类管理器-----------数据库操作的封装
    美团校招的算法题:灯泡游戏
    ccTouchBegan
    特效effects(二)
    特效effects
    CCProgressTo和CCProgressTimer
    TransitionsTest
  • 原文地址:https://www.cnblogs.com/ygm900/p/4578844.html
Copyright © 2011-2022 走看看