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
Related
I'm trying to get the updated status bar frame height using didChangeStatusBarFrame, but…
The new/updated frame isn't up-to-date and sometimes returns the old and sometimes the new (correct) height.
func application(_ application: UIApplication, didChangeStatusBarFrame oldStatusBarFrame: CGRect) {
print(UIApplication.shared.statusBarFrame.height) // Sometimes wrong
}
My current workaround is to use DispatchQueue.main.async:
func application(_ application: UIApplication, didChangeStatusBarFrame oldStatusBarFrame: CGRect) {
DispatchQueue.main.async {
print(UIApplication.shared.statusBarFrame.height) // So far correct in all my tests
}
}
I guess it's because some layout is happening in the background and the statusBarFrame needs to update first.
What's the real reason and is there a better, not-so-hacky way to wait for the correct status bar frame height?
I am moving in from objective c to swift can anyone specify how to stop keyboard to hide the textfield . The problem is I have some text field in my view controller when the user click on last text field near to bottom of screen the keyboard appears and hide the textfield . is there any easy to solve this or should i have to use scroll view ?
Use this library called IQKeyboardManager:
https://github.com/hackiftekhar/IQKeyboardManager
Install pod file pod 'IQKeyboardManager’ . And in your app delegate
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
IQKeyboardManager.shared.enable = true
IQKeyboardManager.shared.enableAutoToolbar = true
IQKeyboardManager.shared.toolbarDoneBarButtonItemText = "Done”
return true
}
}
You can change the following properties of IQKeyboardManager as well
IQKeyboardManager.shared.overrideKeyboardAppearance = true
IQKeyboardManager.shared.keyboardAppearance = .dark
IQKeyboardManager.shared.toolbarBarTintColor = UIColor.cyan
IQKeyboardManager.shared.toolbarDoneBarButtonItemImage = UIImage(named: "<#T##String#>")
IQKeyboardManager.shared.shouldShowToolbarPlaceholder = false
IQKeyboardManager.shared.placeholderFont = UIFont(name: "Times New Roman", size: 20.0)
IQKeyboardManager.shared.shouldResignOnTouchOutside = true
IQKeyboardManager.shared.shouldPlayInputClicks = true //default
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 */
}
getting the statusBarFrame doesn't appear to return the correct value in iOS 11. I realize there may be a nicer way of dealing with this in the future using the Safe Area but right now I really need to get the statusBarFrame to work as it did before iOS 11. Here's how I usually get it.
UIApplication.shared.statusBarFrame
I'v verified that my app works properly before iOS 11. But in iOS 11 it appears to be backwards; for example, for an iPhone in portrait it should 20 and in landscape 0. But it returns 0 in portrait and 20 in landscape.
I've read all the posts regarding status bar issues and none address this problem.
I think it appears to be a timing issue. I wrapped the code that uses the statusBarFrame in a DispatchQueue.main.async {} closure and it works fine. I would consider this more of a bandaid. Still hoping for a proper solution.
Suggestions appreciated.
Thanks!
You can set background color for status bar during application launch or during viewDidLoad of your view controller. Here it works for me, in following ways.
extension UIApplication {
var statusBarView: UIView? {
return value(forKey: "statusBar") as? UIView
}
}
// Set upon application launch, if you've application based status bar
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
return true
}
}
or
// Set it from your view controller if you've view controller based statusbar
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
}
}
Here is result:
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
}