How Does Things 3 Shade Their String String
In Thing 3 , the status bar text (wireless signal, time, battery, etc.) in the iOS app is grayed out. You can usually only have black or white text on the status bar.
How do they do it?
My first guess: they have a translucent white UIView
that covers the status bar, but I'm not sure how they pulled that off. I would like to know how to do this in Swift.
source to share
Here's some sample code in Swift that seems to be very close to the Things 3 state effect. In essence, you create another window to place it right above the state bar, which turns off the color slightly.
Important points to note in this example:
- We assign a new one
UIWindow
to the property, otherwise it will be released as soon as we leave the area. - We set
windowLevel
inUIWindowLevelStatusBar
- We set
isHidden
tofalse
instead of being calledmakeKeyAndVisible
, since we still want the normal window to be the key window
AppDelegate.swift
:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var overlayWindow = UIWindow()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
overlayWindow.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 20)
overlayWindow.windowLevel = UIWindowLevelStatusBar
overlayWindow.backgroundColor = UIColor(white: 1, alpha: 0.4)
overlayWindow.rootViewController = UIViewController()
overlayWindow.isHidden = false
return true
}
}
source to share
I expect them to do it as you say by adding a UIWindow to the status bar. Here is some sample code that does this (in Objective-C.)
http://www.b2cloud.com.au/tutorial/multiple-uiwindows/
UIWindow* topWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[topWindow setWindowLevel:UIWindowLevelAlert];
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
UIViewController* viewController = [[ViewController alloc] init];
UIView* overlay = [[UIView alloc] initWithFrame:CGRectMake(0, -statusBarHeight, viewController.view.frame.size.width, statusBarHeight - 1)];
[overlay setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[overlay setBackgroundColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:0.5]];
[viewController.view addSubview:overlay];
[topWindow setRootViewController:viewController];
[topWindow setHidden:NO];
[topWindow setUserInteractionEnabled:NO];
[viewController release];
viewController = nil;
[overlay release];
overlay = nil;
source to share