首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将全局条件格式应用于iOS中的UISearchBar、UINavigationController、UIToolbar

将全局条件格式应用于iOS中的UISearchBar、UINavigationController、UIToolbar
EN

Stack Overflow用户
提问于 2013-09-24 09:42:05
回答 1查看 179关注 0票数 0

我正在将下一个全局格式应用到我的应用程序中:

代码语言:javascript
复制
-(void)customizeAppearance{

    //Customizing UINavigationBar
    UIImage *navigationbarImage44 = [[UIImage imageNamed:@"navigationbar_44"]
                                resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    UIImage *navigationbarImage32 = [[UIImage imageNamed:@"navigationbar_32"]
                                resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

    //Set the background image for *all* UINavigationBars
    [[UINavigationBar appearance] setBackgroundImage:navigationbarImage44 forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBackgroundImage:navigationbarImage32 forBarMetrics:UIBarMetricsLandscapePhone];

    //Customize the titlebar for *all* the navigationBars
    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                          [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],  UITextAttributeTextColor,
                                                          [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],  UITextAttributeTextShadowColor,
                                                          [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],          UITextAttributeTextShadowOffset,
                                                          [UIFont fontWithName:labelFontName size:0.0],             UITextAttributeFont,
                                                          nil]];




    //Customizing UIToolbar
    UIImage *toolbarImage44 = [[UIImage imageNamed:@"toolbar_44"]
                                     resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    UIImage *toolbarImage32 = [[UIImage imageNamed:@"toolbar_32"]
                                     resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

    [[UIToolbar appearance] setBackgroundImage:toolbarImage44 forToolbarPosition:UIToolbarPositionAny
                                    barMetrics:UIBarMetricsDefault];
    [[UIToolbar appearance] setBackgroundImage:toolbarImage32 forToolbarPosition:UIToolbarPositionAny
                                    barMetrics:UIBarMetricsLandscapePhone];

    //Customizing UIBarButtonItem
    UIImage *button30 = [[UIImage imageNamed:@"buttonitem_30"]
                         resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
    UIImage *button24 = [[UIImage imageNamed:@"buttonitem_24"]
                         resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];


    [[UIBarButtonItem appearance] setBackgroundImage:button30 forState:UIControlStateNormal
                                          barMetrics:UIBarMetricsDefault];
    [[UIBarButtonItem appearance] setBackgroundImage:button24 forState:UIControlStateNormal
                                          barMetrics:UIBarMetricsLandscapePhone];


    //Customizing UIBarButtonItem BackButton
    [[UIBarButtonItem appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],  UITextAttributeTextColor,
      [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],  UITextAttributeTextShadowColor,
      [NSValue valueWithUIOffset:UIOffsetMake(0, 1)],           UITextAttributeTextShadowOffset,
      [UIFont fontWithName:labelFontName size:0.0],     UITextAttributeFont,
      nil]forState:UIControlStateNormal];


    UIImage *buttonBack30 = [[UIImage imageNamed:@"backbuttonitem_30"]
                             resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)];
    UIImage *buttonBack24 = [[UIImage imageNamed:@"backbuttonitem_24"]
                             resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 5)];
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack30
                                                      forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack24
                                                      forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];


    //Customizing UISegmentedControl
    [[UISegmentedControl appearance] setTintColor:(UIColorFromRGB(toolbarTintColor))];

    //Customizing UISearchBar
    [[UISearchBar appearance] setBackgroundImage:navigationbarImage44];
}

我在我的AppDelegate.m方法中调用它

代码语言:javascript
复制
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

    [self customizeAppearance];
    return YES;
}

问题是:

如果viewController不在iPad弹出窗口中,我如何调整所有这些通用格式?

我不希望我的弹出窗口共享原始格式,我希望它们与UINavigationBars、UIToolbars、UIBarButtonItems一起使用。一如既往的黑色

提前感谢您的支持

EN

回答 1

Stack Overflow用户

发布于 2013-09-24 10:44:06

您可以使用appearanceWhenContainedIn:而不是appearance。因此,不是

代码语言:javascript
复制
[[UINavigationBar appearance] setBackgroundImage:navigationbarImage44 forBarMetrics:UIBarMetricsDefault];

代码语言:javascript
复制
[[UINavigationBar appearanceWhenContainedIn:[CustomViewController class]] setBackgroundImage:navigationbarImage44 forBarMetrics:UIBarMetricsDefault];

这会将外观更改限制为仅包含在CustomViewController中的UINavigationBar实例。您可能想要查看this question,了解如何将appearanceWhenContainedIn用于UIBarButtonItem之类的东西。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18971673

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档