我应该在哪里放置我的应用程序范围的UI自定义

时间:2023-01-13 23:06:48

I have a class that I have created to do all the work for customizing appearances. The class is UIAppearance delegate.

我有一个我创建的类来完成自定义外观的所有工作。该班是UIAppearance代表。

UI customization currently affects,

UI自定义目前影响,

  1. Navigation Bar
  2. Search Bar
  3. Tab bar

All these elements will not vary with Views as I can not forsee a situation where I might have different style for any of those.

所有这些元素都不会随着视图的不同而变化,因为我无法预见到这种情况可能与其中任何一种都有不同的风格。

Where and How can I place it to be available application wide and such that I don't have to invoke those methods from everywhere (One time call to affect UI tweaks) ?

在哪里以及如何将它放在应用程序范围内,以便我不必从任何地方调用这些方法(一次性调用以影响UI调整)?

  • by subclassing ?
  • 通过子类化?

  • is AppDelegate a good candidate for this ?
  • AppDelegate是一个很好的候选人吗?

  • importing the subject class and manually invoking the methods
  • 导入主题类并手动调用方法

Is it possible to make one time calls for these customizations ?

是否可以一次性调用这些自定义项?

3 个解决方案

#1


1  

You can do this in -applicationDidFinishLaunching.

您可以在-applicationDidFinishLaunching中执行此操作。

UIKit classes like UINavigationBar give you an appearance proxy when you call appearance on the class:

当您在类上调用外观时,像UINavigationBar这样的UIKit类会为您提供外观代理:

[[UINavigationBar appearance] setTintColor:myColor]; sets myColor as the tintColor for all navigation bars.

[[UINavigationBar外观] setTintColor:myColor];将myColor设置为所有导航栏的tintColor。

See the UIAppearance documentation for more details.

有关更多详细信息,请参阅UIAppearance文档。

#2


1  

This link has some good resources, and example on UIKit customisation. http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-uikit-theme-customization/

这个链接有一些很好的资源,以及UIKit定制的例子。 http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-uikit-theme-customization/

They use applicationDiDFinishLaunching too.

他们也使用applicationDiDFinishLaunching。

#3


1  

you can use singleTon class like SharedManager, Create all this object in it and it will be available through out your application.

你可以使用像SharedManager这样的singleTon类,在其中创建所有这个对象,它将在你的应用程序中可用。

// Step 1: Create a file named "SharedManager.h"

//步骤1:创建名为“SharedManager.h”的文件

#import <Foundation/Foundation.h>

@interface SharedManager : NSObject
{
    UINavigationBar *navBar;
    UISearchBar *searchBar;
}

@property (nonatomic, retain) UINavigationBar *navBar;
@property (nonatomic, retain) UISearchBar *searchBar;

+(SharedManager *)sharedInstance;

@end

// step 2 : create a file : "SharedManager.m"

//第2步:创建一个文件:“SharedManager.m”

#import "SharedManager.h"

static SharedManager *_sharedManager;
@implementation SharedManager

@synthesize navBar , searchBar;

+(SharedManager *)sharedInstance
{
    if(_sharedManager == nil)
    {
        _sharedManager = [[SharedManager alloc] init];

        // Create Navigation Bar
        _sharedManager.navBar = [[UINavigationBar alloc] init];

        // Create Search Bar
        _sharedManager.searchBar = [[UISearchBar alloc] init];
    }

    return _sharedManager;
}

@end

// To access the object use following code, #import "SharedManager.h"

//要访问该对象,请使用以下代码,#import“SharedManager.h”

 [[SharedManager sharedInstance].navBar];

it will return object of NavigationBar

它将返回NavigationBar的对象

#1


1  

You can do this in -applicationDidFinishLaunching.

您可以在-applicationDidFinishLaunching中执行此操作。

UIKit classes like UINavigationBar give you an appearance proxy when you call appearance on the class:

当您在类上调用外观时,像UINavigationBar这样的UIKit类会为您提供外观代理:

[[UINavigationBar appearance] setTintColor:myColor]; sets myColor as the tintColor for all navigation bars.

[[UINavigationBar外观] setTintColor:myColor];将myColor设置为所有导航栏的tintColor。

See the UIAppearance documentation for more details.

有关更多详细信息,请参阅UIAppearance文档。

#2


1  

This link has some good resources, and example on UIKit customisation. http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-uikit-theme-customization/

这个链接有一些很好的资源,以及UIKit定制的例子。 http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-uikit-theme-customization/

They use applicationDiDFinishLaunching too.

他们也使用applicationDiDFinishLaunching。

#3


1  

you can use singleTon class like SharedManager, Create all this object in it and it will be available through out your application.

你可以使用像SharedManager这样的singleTon类,在其中创建所有这个对象,它将在你的应用程序中可用。

// Step 1: Create a file named "SharedManager.h"

//步骤1:创建名为“SharedManager.h”的文件

#import <Foundation/Foundation.h>

@interface SharedManager : NSObject
{
    UINavigationBar *navBar;
    UISearchBar *searchBar;
}

@property (nonatomic, retain) UINavigationBar *navBar;
@property (nonatomic, retain) UISearchBar *searchBar;

+(SharedManager *)sharedInstance;

@end

// step 2 : create a file : "SharedManager.m"

//第2步:创建一个文件:“SharedManager.m”

#import "SharedManager.h"

static SharedManager *_sharedManager;
@implementation SharedManager

@synthesize navBar , searchBar;

+(SharedManager *)sharedInstance
{
    if(_sharedManager == nil)
    {
        _sharedManager = [[SharedManager alloc] init];

        // Create Navigation Bar
        _sharedManager.navBar = [[UINavigationBar alloc] init];

        // Create Search Bar
        _sharedManager.searchBar = [[UISearchBar alloc] init];
    }

    return _sharedManager;
}

@end

// To access the object use following code, #import "SharedManager.h"

//要访问该对象,请使用以下代码,#import“SharedManager.h”

 [[SharedManager sharedInstance].navBar];

it will return object of NavigationBar

它将返回NavigationBar的对象