Iphone 通过外观代理定制UITabbar,而不是直接设置属性(区别、优势…)
定制Iphone 通过外观代理定制UITabbar,而不是直接设置属性(区别、优势…),iphone,ios,uitabbar,uiappearance,Iphone,Ios,Uitabbar,Uiappearance,定制uitabar时,我有两种方法,两种方法都可以但我很好奇,哪种方法最好,两种方法都有哪些优点和缺点 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UITabBarController *tbc = (UITabBarController *)self.window.rootViewControl
uitabar
时,我有两种方法,两种方法都可以但我很好奇,哪种方法最好,两种方法都有哪些优点和缺点
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController *tbc = (UITabBarController *)self.window.rootViewController;
UITabBar *tb = tbc.tabBar;
// 1. Customizing UITabBar using appearance proxy:
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabbar.png"]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected.png"]];
// 2. Doing the same by setting the properties directly:
// tb.backgroundImage = [UIImage imageNamed:@"tabbar.png"];
// tb.selectionIndicatorImage = [UIImage imageNamed:@"tabbar_selected.png"];
return YES;
}
外观代理的优点是,您可以随时更改任何控制器的外观,甚至可以利用它保存一些重绘调用 在视图布局时,您对代理对象所做的任何更改都将应用于已存在或随后创建的类的所有实例。但是,您以后仍然可以使用给定实例的方法和属性覆盖代理默认值。 要使用属性进行访问,您需要该控制器的对象,然后才能访问它。
你也可以检查一下我想你误解了我的问题。我想知道使用
外观代理
与直接使用选项卡属性
如背景图像
的区别/优势。参见示例代码1和2上的注释