1、 例如:设置 UIBarButtonItem在 UINavigationBar 、UIPopoverController 、 UITabbar 中的效 果。就可以这样写UIBarButtonItem appearanceWhenContainedIn:UINavigationBar class, UIPopoverController class,UITabbar class nil setTintColor:myPopoverNavBarColor; 请注意使用appearance设置UI效果最好采用全局的设置, 在所有界面初1.修改导航栏背景代码如下:UINavigationBar * a
2、ppearance = UINavigationBar appearance;UIImage *navBackgroundImg =UIImageimageNamed:navBg.png ” ;appearance setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault;2. 标签栏( UITabbar ) 代码如下:UITabBar *appearance = UITabBar appearance;/设置背景图片UIImage imageNamed:tabbar_bg.png;/ 门置选择 item 的背景
3、图片UIImage * selectionIndicatorImage =UIImage imageNamed:tabbar_sliderresizableImageWithCapInsets:UIEdgeInsetsMake(4, 0, 0, 0) ;appearancesetSelectionIndicatorImage:selectionIndicatorImage;3. 分段控 件( UISegmentControl ) 代码如下:appearance;/Segmenteg 正常背景Segmente.pngforState:UIControlStateNormalbarMetrics:
4、/Segmente 选中背景Segmente_a.pngUIControlStateSelected/Segmente 左右都未选中时的分割线/BarMetrics 表示 navigation bar 的状态, UIBarMetricsDefault表示 portrait 状态( 44pixel height ),UIBarMetricsLandscapePhone 表示 landscape 状态( 32pixel height )appearance setDividerImage:Segmente_line.pngforLeftSegmentState:UIControlStateNorm
5、al rightSegmentState:UIControlStateNormal barMetrics:rightSegmentState:UIControlStateSelected barMetrics:/字体NSDictionary *textAttributes1 = UITextAttributeFont: UIFont systemFontOfSize:18,UITextAttributeTextColor: UIColor blueColor,UITextAttributeTextShadowColor: UIColor whiteColor,UITextAttributeTe
6、xtShadowOffset: NSValue valueWithCGSize:CGSizeMake(1, 1);1;NSDictionary *textAttributes2 = UITextAttributeFont: UIColor blackColor,appearance setTitleTextAttributes:textAttributes20;4.UIBarbutton注意: UIBarbutton 有 leftBarButton , rightBarButton 和独设置。barButton 背景设置是 ios6.0 及以后的,而 backbutton 是 ios5.0及以
7、后的,这里要注意! 代码如下:/ 修改导航条上的 UIBarButtonItemUIBarButtonItem *appearance = UIBarButtonItem appearanceWhenContainedIn:UINavigationBar class, nil;/ 设置导航栏的字体包括 backBarButton 和 leftBarButton ,rightBarButton 的字体NSDictionary *textAttributes = UITextAttributeFont:textAttributes/forState 为 0 时为下正常状态,为 1 时为点击状 态。
8、/ 修改 leftBarButton ,rightBarButton 背景效果navBarButton.pngstyle:UIBarButtonItemStyleBorderednavBarButton_a.pngUIControlStateHighlighted/backBarButton 需要单独设置背景效果。只能在 ios6.0 以 后才能用appearance setBackButtonBackgroundImage:nav_bg.png forState:work.png1-1)forBarMetrics:5. 工具栏UIToolbar ) UIToolbar *appearance = UIToolbar appearance;/样式和背景二选一即可,看需求了/样式(黑色半透明,不透明等)设置appearance setBarStyle:UIBarStyleBlackTranslucent;/背景设置toolbarBg.png forToolbarPosition:UIToolbarPositionAny
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1