Yes, there is a new way to do this. You can use appearance
to make all UIToolBar
s have the same appearance.
First, you have to make sure your class follows the UIAppearanceContainer
protocol. Here I have done it in my app delegate:
@interface AppDelegate : UIResponder <UIApplicationDelegate, UIAppearanceContainer>
@property (strong, nonatomic) UIWindow *window;
@end
Then you can set the appearance in, for example, application:didFinishLaunchingWithOptions:
or viewDidLoad
. Like this:
UIImage *image = [UIImage imageNamed:@"myimage.png"];
[[UIToolbar appearance] setBackgroundImage:image forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
You only have to do this once to get the same appearance for all UIToolBar
s in your app. You can also set many of (if not all?) the properties of your UIToolBar
.
As a sidenote, there are many classes that can follow the UIAppearanceContainer
protocol. To find out what can be customized using the appearance protocol, you can open the header file of the class you want to customize, if you can set a property with UIAppearance
, then the property has UI_APPEARANCE_SELECTOR
written behind the property declaration.