Change default global tint color in swift

℡╲_俬逩灬. 提交于 2020-01-31 04:49:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!