I'm starting Developing for iOS and I want to know if someone knows how to change the status bar color like Youtube or Hangout apps do. I think that is overlaying a view but I do not know how to do it.
Thanks for all :).
Example 1: Hangout.
Example 2: Youtube.
Yes you'll need an overlay, it's how I would do to have an effect like in your examples:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let view: UIView = UIView.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, 20))
// We will apply a transparent black color to darken the status bar
view.backgroundColor = UIColor.blackColor()
view.alpha = 0.1
self.window!.rootViewController!.view.addSubview(view)
return true
}
Related
I am using this Github-Repo for a reavealing splash view.
I am calling it like this inside my AppDelegate:
let revealingSplashView = RevealingSplashView(iconImage: UIImage(named: "wIcon")!, iconInitialSize: CGSize(width: 120 * UIScreen.main.bounds.width / 414.0, height: 120 * UIScreen.main.bounds.width / 414.0), backgroundColor: .white)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
revealingSplashView.startAnimation()
window?.rootViewController?.view.addSubview(revealingSplashView)
return true
}
I am facing an issue where sometimes after the animation is finished, it is not instantly transitioning to the other ViewController but showing a blank white screen.
Here is a screen-video for a better understanding.
Does anyone have an idea what can cause that?
Or is there an easy way to implement it without this repo?
You calling the revealingSplashView inside AppDelegate didFinishLaunchingWithOptions. If you check the documentation they clearly state to call it in the viewDidLoad method of your viewController. Your view has not been loaded that's why you got the delay.
Check the documentation which you linked above:
import RevealingSplashView
override func viewDidLoad() {
super.viewDidLoad()
//Initialize a revealing Splash with with the iconImage, the initial size and the background color
let revealingSplashView = RevealingSplashView(iconImage: UIImage(named: "twitterLogo")!,iconInitialSize: CGSize(width: 70, height: 70), backgroundColor: UIColor(red:0.11, green:0.56, blue:0.95, alpha:1.0))
//Adds the revealing splash view as a sub view
self.view.addSubview(revealingSplashView)
This question already has an answer here:
How to set color of status bar showing carrier, time, and battery on top
(1 answer)
Closed 3 years ago.
When I scroll down Status bar across my text, and its seems terribly
Can I make a status bar background grey or dark and text of status bar light?
The style of the status bar can be changed to a status bar with white content. Go to the ViewController.swift file and add the following lines of code.
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
enum UIStatusBarStyle : Int
case default : A dark status bar, intended for use on light
backgrounds.
case lightContent : A light status bar, intended for use on dark
backgrounds.
case darkContent : A dark status bar, intended for use on light
backgrounds.
If you want to change the background color of the status bar together, you can do the following:
if #available(iOS 13.0, *) {
let statusBarView = UIView(frame: view.window?.windowScene?.statusBarManager?.statusBarFrame ?? CGRect.zero)
statusBarView.backgroundColor = backgroundColor
view.addSubview(statusBarView)
} else {
// Fallback on earlier versions
let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)
statusBarView.backgroundColor = backgroundColor
view.addSubview(statusBarView)
}
add in your appDelegate this code
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UINavigationBar.appearance().barStyle = .blackOpaque
return true
}
or in your info plist use
or in specific view
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
navigationController?.navigationBar.barStyle = .blackOpaque
}
for view controller
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
I am using Eureka to implement a simple form in my project. The form seems to have blue tint in the tint bar buttons above the keyboard and I am unsure how to change it.
Is there a way to make the "Done" label green like the rest of my UI?
Updated Eureka 4.3.x
You should override a variable customNavigationAccessoryView in your controller
override var customNavigationAccessoryView: (UIView & NavigationAccessory)? {
// The width might not be correctly defined yet: (Normally you can use UIScreen.main.bounds)
let navView = NavigationAccessoryView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 44.0))
navView.barTintColor = UIColor.MaterialColors.category3
navView.tintColor = UIColor.white
return navView
}
Here you go and fix the colour of Done Label.
override NaviagtionAccessoryView Instance as navigationAccessoryView below
navigationAccessoryView.tintColor = "Your Colour"
navigationAccessoryView.backgroundColor = "Your Colour"
navigationAccessoryView.doneButton.tintColor = "Your Colour"
More Here
You can set a default tint color for all UIView instance by
UIView.appearance().tintColor = .red
appearance() is a method in UIAppearance protocol. UIView and its subclasses confirm to this protocol. You can also do
UIButton.appearance().tintColor = .green
Add the below line in AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
self.window?.tintColor = UIColor.black // You can set it to which color you want.
return true
}
All the tint color of the whole app will be changed to the given color.
This works for me perfectly:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
NavigationAccessoryView.appearance().tintColor = /* your color here */
}
I am experiencing a strange issue using IQKeyboardManager when keyboard split mode is enabled. Keyboard's background isn't transparent:
But keyboard's background is transparent when IQKeyboardManager is not used:
EDIT How to reproduce:
//AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
...
IQKeyboardManager.shared.enable = true
...
}
//ViewController.swift
override func viewDidLoad() {
...
textField.keyboardDistanceFromTextField = 140 // or any constant
...
}
Any suggestion? Thanks!
I got an answer from IQKeyboardManager library's maintainer (answer).
Keyboard's background is fully transparent if you disable autoToolbar:
IQKeyboardManager.shared.enableAutoToolbar = false
I am working on styling the app I'm building. I want to apply some system-wide styling (fonts) to the tab bar and then in some instances style things like colour. I'm running into two problems:
When you set any titleTextAttributes using setTitleTextAttributes:forState: on an instance of a UITabBar, it immediately ignores any titleTextAttributes set on the appearance proxy (including keys that were not set on the instance, but set on the appearance proxy).
// AppDelegate
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UITabBarItem.appearance().setTitleTextAttributes([
NSFontAttributeName: UIFont(name: "Lato-Regular", size: 20.0)!
], forState: .Normal)
}
// Later on in a ViewController that has a UITabBar
override func viewDidLoad() {
myTabBar.setTitleTextAttributes([
NSForegroundColorAttributeName: UIColor.blueColor()
], forState: .Normal)
// Tab bar items now have blue text, but Helvetica Neue font
// We've lost the appearance proxy font (Lato-Regular)
}
In order to fix (1) I was just going to copy the titleTextAttributes from the appearance proxy and then overwrite them with whatever attributes I wanted to apply on the instance. Eg.
// AppDelegate
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UITabBarItem.appearance().setTitleTextAttributes([
NSFontAttributeName: UIFont(name: "Lato-Regular", size: 20.0)!
], forState: .Normal)
}
// Later on in a ViewController that has a UITabBar
override func viewDidLoad() {
var attributes = UITabBarItem.appearance().titleTextAttributesForState(state) ?? [NSObject: AnyObject]()
assert(attributes.count > 0, "Could not read titleTextAttributes set on appearance proxy!")
}
This is most annoying because you can read appearance proxy values on UINavigationBar just fine.
Any ideas?