Skip to content

Commit

Permalink
- Adopted Light Move and Dark Mode in keyboard toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
hackiftekhar committed Sep 7, 2019
1 parent 3f31c45 commit c6bb989
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 77 deletions.
4 changes: 2 additions & 2 deletions Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@
PRODUCT_NAME = DemoSwift;
SWIFT_OBJC_BRIDGING_HEADER = "Demo/Swift_Demo/Resources/IQKeyboardManger-Swift-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -1169,7 +1169,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.iftekhar.IQKeyboardManagerSwift;
PRODUCT_NAME = DemoSwift;
SWIFT_OBJC_BRIDGING_HEADER = "Demo/Swift_Demo/Resources/IQKeyboardManger-Swift-Bridging-Header.h";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
6 changes: 2 additions & 4 deletions Demo.xcodeproj/xcshareddata/xcschemes/DemoSwift.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -38,8 +36,8 @@
ReferencedContainer = "container:Demo.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down
8 changes: 4 additions & 4 deletions IQKeyboardManager/IQKeyboardManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ extern NSInteger const kIQPreviousNextButtonToolbarTag;
@property(nonatomic, assign) IQAutoToolbarManageBehaviour toolbarManageBehaviour;

/**
If YES, then uses textField's tintColor property for IQToolbar, otherwise tint color is black. Default is NO.
If YES, then uses textField's tintColor property for IQToolbar, otherwise tint color is nil. Default is NO.
*/
@property(nonatomic, assign) BOOL shouldToolbarUsesTextFieldTintColor;

/**
This is used for toolbar.tintColor when textfield.keyboardAppearance is UIKeyboardAppearanceDefault. If shouldToolbarUsesTextFieldTintColor is YES then this property is ignored. Default is nil and uses black color.
This is used for toolbar.tintColor when textfield.keyboardAppearance is UIKeyboardAppearanceDefault. If shouldToolbarUsesTextFieldTintColor is YES then this property is ignored. Default is nil.
*/
@property(nullable, nonatomic, strong) UIColor *toolbarTintColor;

/**
This is used for toolbar.barTintColor. Default is nil and uses white color.
This is used for toolbar.barTintColor. Default is nil.
*/
@property(nullable, nonatomic, strong) UIColor *toolbarBarTintColor;

Expand Down Expand Up @@ -172,7 +172,7 @@ extern NSInteger const kIQPreviousNextButtonToolbarTag;
@property(nullable, nonatomic, strong) UIColor *placeholderColor;

/**
Placeholder Button Color when it's treated as button. Default is nil. Which means iOS Blue for light toolbar and Yellow for dark toolbar
Placeholder Button Color when it's treated as button. Default is nil
*/
@property(nullable, nonatomic, strong) UIColor *placeholderButtonColor;

Expand Down
16 changes: 7 additions & 9 deletions IQKeyboardManager/IQKeyboardManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ -(void)adjustPosition
// Getting KeyWindow object.
UIWindow *keyWindow = [self keyWindow];

// We are unable to get textField object while keyboard showing on UIWebView's textField. (Bug ID: #11)
// We are unable to get textField object while keyboard showing on WKWebView's textField. (Bug ID: #11)
if (_hasPendingAdjustRequest == NO ||
textFieldView == nil ||
rootController == nil ||
Expand Down Expand Up @@ -1361,8 +1361,8 @@ - (void)keyboardWillHide:(NSNotification*)aNotification
CFTimeInterval startTime = CACurrentMediaTime();
[self showLog:[NSString stringWithFormat:@"****** %@ started ******",NSStringFromSelector(_cmd)] indentation:1];

//Commented due to #56. Added all the conditions below to handle UIWebView's textFields. (Bug ID: #56)
// We are unable to get textField object while keyboard showing on UIWebView's textField. (Bug ID: #11)
//Commented due to #56. Added all the conditions below to handle WKWebView's textFields. (Bug ID: #56)
// We are unable to get textField object while keyboard showing on WKWebView's textField. (Bug ID: #11)
// if (_textFieldView == nil) return;

//Restoring the contentOffset of the lastScrollView
Expand Down Expand Up @@ -2015,7 +2015,7 @@ -(void)addToolbarIfRequired
case UIKeyboardAppearanceDark:
{
toolbar.barStyle = UIBarStyleBlack;
[toolbar setTintColor:[UIColor whiteColor]];
[toolbar setTintColor:nil];
[toolbar setBarTintColor:nil];
}
break;
Expand All @@ -2035,7 +2035,7 @@ -(void)addToolbarIfRequired
}
else
{
toolbar.tintColor = [UIColor blackColor];
toolbar.tintColor = nil;
}
}
break;
Expand All @@ -2060,15 +2060,13 @@ -(void)addToolbarIfRequired
}

//Setting toolbar title color. // (Enhancement ID: #880)
if (_placeholderColor &&
[_placeholderColor isKindOfClass:[UIColor class]])
if (_placeholderColor)
{
[toolbar.titleBarButton setTitleColor:_placeholderColor];
}

//Setting toolbar button title color. // (Enhancement ID: #880)
if (_placeholderButtonColor &&
[_placeholderButtonColor isKindOfClass:[UIColor class]])
if (_placeholderButtonColor)
{
[toolbar.titleBarButton setSelectableTitleColor:_placeholderButtonColor];
}
Expand Down
3 changes: 2 additions & 1 deletion IQKeyboardManager/IQTextView/IQTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ -(UILabel*)placeholderLabel
_placeholderLabel.font = self.font;
_placeholderLabel.textAlignment = self.textAlignment;
_placeholderLabel.backgroundColor = [UIColor clearColor];
_placeholderLabel.textColor = [UIColor colorWithWhite:0.7 alpha:1.0];
_placeholderLabel.textColor = [UIColor lightTextColor];
// _placeholderLabel.textColor = [UIColor systemGrayColor]; //iOS 13
_placeholderLabel.alpha = 0;
[self addSubview:_placeholderLabel];
}
Expand Down
2 changes: 2 additions & 0 deletions IQKeyboardManager/IQToolbar/IQTitleBarButtonItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ -(nonnull instancetype)initWithTitle:(nullable NSString *)title
_titleButton.enabled = NO;
_titleButton.titleLabel.numberOfLines = 3;
[_titleButton setTitleColor:[UIColor colorWithRed:0.0 green:0.5 blue:1.0 alpha:1.0] forState:UIControlStateNormal];
// [_titleButton setTitleColor:[UIColor systemBlueColor] forState:UIControlStateNormal]; //iOS 13
[_titleButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
[_titleButton setBackgroundColor:[UIColor clearColor]];
[_titleButton.titleLabel setTextAlignment:NSTextAlignmentCenter];
Expand Down Expand Up @@ -120,6 +121,7 @@ -(void)setSelectableTitleColor:(UIColor*)selectableTitleColor
{
_selectableTitleColor = selectableTitleColor;
[_titleButton setTitleColor:_selectableTitleColor?:[UIColor colorWithRed:0.0 green:0.5 blue:1.0 alpha:1.0] forState:UIControlStateNormal];
// [_titleButton setTitleColor:_selectableTitleColor?:[UIColor systemBlueColor] forState:UIControlStateNormal]; //iOS 13
}

-(void)setInvocation:(NSInvocation *)invocation
Expand Down
23 changes: 0 additions & 23 deletions IQKeyboardManager/IQToolbar/IQToolbar.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@
#import <UIKit/UIAccessibility.h>
#import <UIKit/UIViewController.h>

@interface IQTitleBarButtonItem (PrivateAccessor)

@property(nonnull, nonatomic, strong) UIButton *titleButton;

@end

@implementation IQToolbar
@synthesize previousBarButton = _previousBarButton;
@synthesize nextBarButton = _nextBarButton;
Expand Down Expand Up @@ -162,23 +156,6 @@ -(CGSize)sizeThatFits:(CGSize)size
return sizeThatFit;
}

-(void)setBarStyle:(UIBarStyle)barStyle
{
[super setBarStyle:barStyle];

if (self.titleBarButton.selectableTitleColor == nil)
{
if (barStyle == UIBarStyleDefault)
{
[self.titleBarButton.titleButton setTitleColor:[UIColor colorWithRed:0.0 green:0.5 blue:1.0 alpha:1.0] forState:UIControlStateNormal];
}
else
{
[self.titleBarButton.titleButton setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
}
}
}

-(void)setTintColor:(UIColor *)tintColor
{
[super setTintColor:tintColor];
Expand Down
28 changes: 14 additions & 14 deletions IQKeyboardManagerSwift/IQKeyboardManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ Codeless drop-in universal library allows to prevent issues of keyboard sliding
@objc public var toolbarManageBehaviour = IQAutoToolbarManageBehaviour.bySubviews

/**
If YES, then uses textField's tintColor property for IQToolbar, otherwise tint color is black. Default is NO.
If YES, then uses textField's tintColor property for IQToolbar, otherwise tint color is default. Default is NO.
*/
@objc public var shouldToolbarUsesTextFieldTintColor = false

Expand All @@ -266,7 +266,7 @@ Codeless drop-in universal library allows to prevent issues of keyboard sliding
@objc public var toolbarTintColor: UIColor?

/**
This is used for toolbar.barTintColor. Default is nil and uses white color.
This is used for toolbar.barTintColor. Default is nil.
*/
@objc public var toolbarBarTintColor: UIColor?

Expand Down Expand Up @@ -307,7 +307,7 @@ Codeless drop-in universal library allows to prevent issues of keyboard sliding
@objc public var placeholderColor: UIColor?

/**
Placeholder Button Color when it's treated as button. Default is nil. Which means iOS Blue for light toolbar and Yellow for dark toolbar
Placeholder Button Color when it's treated as button. Default is nil.
*/
@objc public var placeholderButtonColor: UIColor?

Expand Down Expand Up @@ -927,7 +927,7 @@ Codeless drop-in universal library allows to prevent issues of keyboard sliding
/* Adjusting RootViewController's frame according to interface orientation. */
private func adjustPosition() {

// We are unable to get textField object while keyboard showing on UIWebView's textField. (Bug ID: #11)
// We are unable to get textField object while keyboard showing on WKWebView's textField. (Bug ID: #11)
if _privateHasPendingAdjustRequest == true,
let textFieldView = _textFieldView,
let rootController = textFieldView.parentContainerViewController(),
Expand Down Expand Up @@ -1615,8 +1615,8 @@ Codeless drop-in universal library allows to prevent issues of keyboard sliding
let startTime = CACurrentMediaTime()
showLog("****** \(#function) started ******", indentation: 1)

//Commented due to #56. Added all the conditions below to handle UIWebView's textFields. (Bug ID: #56)
// We are unable to get textField object while keyboard showing on UIWebView's textField. (Bug ID: #11)
//Commented due to #56. Added all the conditions below to handle WKWebView's textFields. (Bug ID: #56)
// We are unable to get textField object while keyboard showing on WKWebView's textField. (Bug ID: #11)
// if (_textFieldView == nil) return

//Restoring the contentOffset of the lastScrollView
Expand Down Expand Up @@ -2014,11 +2014,11 @@ Codeless drop-in universal library allows to prevent issues of keyboard sliding
switch textField.keyboardAppearance {

case .dark:
toolbar.barStyle = UIBarStyle.black
toolbar.tintColor = UIColor.white
toolbar.barStyle = .black
toolbar.tintColor = nil
toolbar.barTintColor = nil
default:
toolbar.barStyle = UIBarStyle.default
toolbar.barStyle = .default
toolbar.barTintColor = toolbarBarTintColor

//Setting toolbar tintColor // (Enhancement ID: #30)
Expand All @@ -2027,7 +2027,7 @@ Codeless drop-in universal library allows to prevent issues of keyboard sliding
} else if let tintColor = toolbarTintColor {
toolbar.tintColor = tintColor
} else {
toolbar.tintColor = UIColor.black
toolbar.tintColor = nil
}
}
} else if let textView = textField as? UITextView {
Expand All @@ -2036,19 +2036,19 @@ Codeless drop-in universal library allows to prevent issues of keyboard sliding
switch textView.keyboardAppearance {

case .dark:
toolbar.barStyle = UIBarStyle.black
toolbar.tintColor = UIColor.white
toolbar.barStyle = .black
toolbar.tintColor = nil
toolbar.barTintColor = nil
default:
toolbar.barStyle = UIBarStyle.default
toolbar.barStyle = .default
toolbar.barTintColor = toolbarBarTintColor

if shouldToolbarUsesTextFieldTintColor {
toolbar.tintColor = textView.tintColor
} else if let tintColor = toolbarTintColor {
toolbar.tintColor = tintColor
} else {
toolbar.tintColor = UIColor.black
toolbar.tintColor = nil
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion IQKeyboardManagerSwift/IQTextView/IQTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ open class IQTextView: UITextView {
label.font = self.font
label.textAlignment = self.textAlignment
label.backgroundColor = UIColor.clear
label.textColor = UIColor(white: 0.7, alpha: 1.0)
label.textColor = UIColor.lightText
// label.textColor = UIColor.systemGray //For iOS13
label.alpha = 0
self.addSubview(label)

Expand Down
6 changes: 4 additions & 2 deletions IQKeyboardManagerSwift/IQToolbar/IQTitleBarButtonItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ open class IQTitleBarButtonItem: IQBarButtonItem {
if let color = selectableTitleColor {
titleButton?.setTitleColor(color, for: .normal)
} else {
titleButton?.setTitleColor(UIColor.init(red: 0.0, green: 0.5, blue: 1.0, alpha: 1), for: .normal)
titleButton?.setTitleColor(UIColor(red: 0.0, green: 0.5, blue: 1.0, alpha: 1), for: .normal)
// titleButton?.setTitleColor(UIColor.systemBlue, for: .normal) //iO S13
}
}
}
Expand Down Expand Up @@ -110,7 +111,8 @@ open class IQTitleBarButtonItem: IQBarButtonItem {
titleButton?.isEnabled = false
titleButton?.titleLabel?.numberOfLines = 3
titleButton?.setTitleColor(UIColor.lightGray, for: .disabled)
titleButton?.setTitleColor(UIColor.init(red: 0.0, green: 0.5, blue: 1.0, alpha: 1), for: .normal)
titleButton?.setTitleColor(UIColor(red: 0.0, green: 0.5, blue: 1.0, alpha: 1), for: .normal)
// titleButton?.setTitleColor(UIColor.systemBlue, for: .normal) //iOS 13
titleButton?.backgroundColor = UIColor.clear
titleButton?.titleLabel?.textAlignment = .center
titleButton?.setTitle(title, for: .normal)
Expand Down
13 changes: 0 additions & 13 deletions IQKeyboardManagerSwift/IQToolbar/IQToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,6 @@ open class IQToolbar: UIToolbar, UIInputViewAudioFeedback {
}
}

@objc override open var barStyle: UIBarStyle {
didSet {

if titleBarButton.selectableTitleColor == nil {
if barStyle == .default {
titleBarButton.titleButton?.setTitleColor(UIColor.init(red: 0.0, green: 0.5, blue: 1.0, alpha: 1), for: .normal)
} else {
titleBarButton.titleButton?.setTitleColor(UIColor.yellow, for: .normal)
}
}
}
}

@objc override open func layoutSubviews() {

super.layoutSubviews()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,18 +460,18 @@ UIView category methods to add IQToolbar on UIKeyboard.

switch textField.keyboardAppearance {
case .dark:
toolbar.barStyle = UIBarStyle.black
toolbar.barStyle = .black
default:
toolbar.barStyle = UIBarStyle.default
toolbar.barStyle = .default
}
} else if let textView = self as? UITextView {
textView.inputAccessoryView = toolbar

switch textView.keyboardAppearance {
case .dark:
toolbar.barStyle = UIBarStyle.black
toolbar.barStyle = .black
default:
toolbar.barStyle = UIBarStyle.default
toolbar.barStyle = .default
}
}
}
Expand Down

0 comments on commit c6bb989

Please sign in to comment.