问题
I'm developing a little app and I would like to change the default global tint color from blue to orange. I've seen many ways to do it in Objective-C but I can't seem to get it to work using swift. How could I achieve this? Thanks in advance!
回答1:
Couldn't that be easier?
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
// ...
self.window!.tintColor = UIColor.orangeColor()
return true
}
}
This is the Swift equivalent of Objective-C:
@interface AppDelegate <UIResponder, UIApplicationDelegate>
@property (nonatomic, strong) UIWindow *window;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// ...
self.window.tintColor = [UIColor orangeColor];
return YES;
}
@end
If you're using storyboards, don't put any code in the AppDelegate
, just change the "Global Tint" attribute of the storyboard:
来源:https://stackoverflow.com/questions/25094976/change-default-global-tint-color-in-swift