How to move text field up when keyboard pops up - ios

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

Related

Eureka Forms: How to change form global tint colour

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 */
}

IQKeyboardManager – wrong keyboard layout when split view is enabled

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

iOS UILabel.appearance().textColor is not available

I am trying to change default text color for all labels in my app. I have tried to use UILabel.appearance().textColor, but it's not available for me. Can somebody advise what am I doing wrong? I have checked a lot of questions on SO, the latest one is this. And as per description it's available.
If I changed background color - it works. Tried to change tintColor - no effect. Why? Was it removed from UIAppearance protocol?
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
var window: UIWindow?
var smStore: SMStore?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// UIAppearance configuring
let tintColor = UIColor.white
//let backgroundColor = UIColor(red: 5, green: 72, blue: 149, alpha: 1)
let backgroundColor = UIColor.black
// Global tintColor
window?.tintColor = tintColor
// UIViews
UIView.appearance().tintColor = tintColor
UIView.appearance().backgroundColor = backgroundColor
// UINavigationBars
UINavigationBar.appearance().tintColor = tintColor
UINavigationBar.appearance().backgroundColor = tintColor
// UITableViews
UITableView.appearance().backgroundColor = backgroundColor
UITableViewCell.appearance().backgroundColor = backgroundColor
UITableViewCell.appearance().tintColor = tintColor
// UILabels
UILabel.appearance().backgroundColor = UIColor.green
...
}
Xcode 9, Swift 4.
Just type it in. It compiles.
UILabel.appearance().textColor = .red

How to fix iPhoneX back button image position?

I am getting issue with iPhoneX back button image. It is not in right position as you can see in the screenshot
I am using below code for setting back image
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UINavigationBar.appearance().backIndicatorImage = #imageLiteral(resourceName: "btn-back")
UINavigationBar.appearance().backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "btn-back")
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -80.0), for: .default)
return true
}
}
Can anyone please explain why it's not at correct position and how to fix this ?
You can use topItem?.title for setting up Navigation title as:
Method 1:
self.navigationController?.navigationBar.topItem?.title = ""
Output:
Method 2:
let yourBackImage = UIImage(named: "back-Image")
self.navigationController?.navigationBar.tintColor = .red//.blue as you required
self.navigationController?.navigationBar.backIndicatorImage = yourBackImage
self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = yourBackImage
self.navigationController?.navigationBar.topItem?.title = ""
Output:
Note: As Apple Human Interface GuideLine The navigation bar back image size should be-
75px × 75px(3x)
Sample image 3x(75 x 75)-

Can't read titleTextAttributes on appearance for UITabBarItem

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?

Resources