Skip to content

Commit

Permalink
Adopted subscript syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
hackiftekhar committed Apr 22, 2016
1 parent 8646717 commit 2d27f52
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 237 deletions.
2 changes: 1 addition & 1 deletion Demo/Objective_C_Demo/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>4.0.1</string>
<string>4.0.2</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIMainStoryboardFile</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forC
UILabel *labelText = [[UILabel alloc] init];
[labelText setTextAlignment:NSTextAlignmentCenter];
[labelText setAdjustsFontSizeToFitWidth:YES];
[labelText setText:[_ItemListsInternal objectAtIndex:row]];
[labelText setText:_ItemListsInternal[row]];
labelText.backgroundColor = [UIColor clearColor];

if (self.isOptionalDropDown && row == 0)
Expand All @@ -167,7 +167,7 @@ - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forC

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
[self setSelectedItem:[_ItemListsInternal objectAtIndex:row]];
[self setSelectedItem:_ItemListsInternal[row]];
}

#pragma mark - UIDatePicker delegate
Expand Down Expand Up @@ -211,7 +211,7 @@ - (void)setSelectedRow:(NSInteger)row animated:(BOOL)animated
}
else
{
self.text = [_ItemListsInternal objectAtIndex:row];
self.text = _ItemListsInternal[row];
}

[self.pickerView selectRow:row inComponent:0 animated:animated];
Expand Down Expand Up @@ -404,7 +404,7 @@ -(void)setIsOptionalDropDown:(BOOL)isOptionalDropDown

if (_isOptionalDropDown)
{
NSArray *array = [NSArray arrayWithObject:@"Select"];
NSArray *array = @[@"Select"];
_ItemListsInternal = [array arrayByAddingObjectsFromArray:_itemList];
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
{
OptionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([OptionTableViewCell class])];

cell.labelOption.text = [self.options objectAtIndex:indexPath.row];
cell.labelOption.text = (self.options)[indexPath.row];

cell.accessoryType = (indexPath.row == self.selectedIndex) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;

Expand Down
147 changes: 57 additions & 90 deletions Demo/Objective_C_Demo/ViewController/Settings/SettingsViewController.m

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}

UITextField *textField = (UITextField *)[cell.contentView viewWithTag:123];
textField.placeholder = [NSString stringWithFormat:@"Cell %@",[NSNumber numberWithInteger:indexPath.row]];
textField.placeholder = [NSString stringWithFormat:@"Cell %@",@(indexPath.row)];

return cell;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (void)viewDidLoad
returnKeyHandler = [[IQKeyboardReturnKeyHandler alloc] initWithViewController:self];
[returnKeyHandler setLastTextFieldReturnKeyType:UIReturnKeyDone];

[dropDownTextField setItemList:[NSArray arrayWithObjects:@"Zero Line Of Code",
[dropDownTextField setItemList:@[@"Zero Line Of Code",
@"No More UIScrollView",
@"No More Subclasses",
@"No More Manual Work",
Expand All @@ -78,7 +78,7 @@ - (void)viewDidLoad
@"Auto adjust textView's height ",
@"Adopt tintColor from textField",
@"Customize keyboardAppearance",
@"play sound on next/prev/done",nil]];
@"play sound on next/prev/done"]];
}

-(void)viewWillAppear:(BOOL)animated
Expand Down Expand Up @@ -120,10 +120,7 @@ - (IBAction)presentClicked:(id)sender
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
navigationController.navigationBar.tintColor = self.navigationController.navigationBar.tintColor;

#ifdef NSFoundationVersionNumber_iOS_6_1
navigationController.navigationBar.barTintColor = self.navigationController.navigationBar.barTintColor;
#endif
navigationController.navigationBar.titleTextAttributes = self.navigationController.navigationBar.titleTextAttributes;

[navigationController setModalTransitionStyle:arc4random()%4];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ - (void)viewDidLoad
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
_data = [NSArray arrayWithObjects:@"Hello", @"This is a demo code", @"Issue #56", @"With mutiple cells", @"And some useless text.",
_data = @[@"Hello", @"This is a demo code", @"Issue #56", @"With mutiple cells", @"And some useless text.",
@"Hello", @"This is a demo code", @"Issue #56", @"With mutiple cells", @"And some useless text.",
@"Hello", @"This is a demo code", @"Issue #56", @"With mutiple cells", @"And some useless text.",nil];
@"Hello", @"This is a demo code", @"Issue #56", @"With mutiple cells", @"And some useless text."];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Expand Down Expand Up @@ -50,7 +50,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(5,7,135,30)];
textView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
textView.backgroundColor = [UIColor clearColor];
textView.text = [_data objectAtIndex:indexPath.row];
textView.text = _data[indexPath.row];
textView.dataDetectorTypes = UIDataDetectorTypeAll;
textView.scrollEnabled = NO;
textView.editable = NO;
Expand Down
2 changes: 1 addition & 1 deletion Demo/Swift_Demo/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>4.0.1</string>
<string>4.0.2</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIMainStoryboardFile</key>
Expand Down
27 changes: 2 additions & 25 deletions Demo/Swift_Demo/ViewController/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SettingsViewController: UITableViewController, OptionsViewControllerDelega
let keyboardManagerProperties = [
["Enable", "Keyboard Distance From TextField", "Prevent Showing Bottom Blank Space"],
["Enable AutoToolbar","Toolbar Manage Behaviour","Should Toolbar Uses TextField TintColor","Should Show TextField Placeholder","Placeholder Font"],
["Can Adjust TextView","Should Fix TextView Clip"],
["Can Adjust TextView"],
["Override Keyboard Appearance","UIKeyboard Appearance"],
["Should Resign On Touch Outside"],
["Should Play Input Clicks"],
Expand All @@ -30,7 +30,7 @@ class SettingsViewController: UITableViewController, OptionsViewControllerDelega
let keyboardManagerPropertyDetails = [
["Enable/Disable IQKeyboardManager","Set keyboard distance from textField","Prevent to show blank space between UIKeyboard and View"],
["Automatic add the IQToolbar on UIKeyboard","AutoToolbar previous/next button managing behaviour","Uses textField's tintColor property for IQToolbar","Add the textField's placeholder text on IQToolbar","UIFont for IQToolbar placeholder text"],
["Adjust textView's frame when it is too big in height","Adjust textView's contentInset to fix a bug"],
["Adjust textView's frame when it is too big in height"],
["Override the keyboardAppearance for all UITextField/UITextView","All the UITextField keyboardAppearance is set using this property"],
["Resigns Keyboard on touching outside of UITextField/View"],
["Plays inputClick sound on next/previous/done click"],
Expand Down Expand Up @@ -93,13 +93,6 @@ class SettingsViewController: UITableViewController, OptionsViewControllerDelega
self.tableView.reloadSections(NSIndexSet(index: 0), withRowAnimation: UITableViewRowAnimation.Fade)
}

func shouldFixTextViewClipAction (sender: UISwitch) {

IQKeyboardManager.sharedManager().shouldFixTextViewClip = sender.on

self.tableView.reloadSections(NSIndexSet(index: 3), withRowAnimation: UITableViewRowAnimation.Fade)
}

/** "Keyboard appearance overriding */
func overrideKeyboardAppearanceAction (sender: UISwitch) {

Expand Down Expand Up @@ -329,22 +322,6 @@ class SettingsViewController: UITableViewController, OptionsViewControllerDelega
cell.switchEnable.addTarget(self, action: #selector(self.canAdjustTextViewAction(_:)), forControlEvents: UIControlEvents.ValueChanged)

return cell

case 1:

let cell = tableView.dequeueReusableCellWithIdentifier("SwitchTableViewCell") as! SwitchTableViewCell
cell.switchEnable.enabled = true

cell.labelTitle.text = keyboardManagerProperties[indexPath.section][indexPath.row]
cell.labelSubtitle.text = keyboardManagerPropertyDetails[indexPath.section][indexPath.row]

cell.switchEnable.on = IQKeyboardManager.sharedManager().shouldFixTextViewClip

cell.switchEnable.removeTarget(nil, action: nil, forControlEvents: UIControlEvents.AllEvents)
cell.switchEnable.addTarget(self, action: #selector(self.shouldFixTextViewClipAction(_:)), forControlEvents: UIControlEvents.ValueChanged)

return cell

default:
break
}
Expand Down
9 changes: 0 additions & 9 deletions DemoObjCUITests/DemoObjCUITests.m
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,6 @@ - (void)testTextFieldPlaceholder {
[keyboardDoneButton tap];
}


/////--------------------------
///// @name UITextView handling
/////--------------------------
//
///**
// canAdjustTextView Adjust textView's frame when it is too big in height. Default is NO.
// shouldFixTextViewClip Adjust textView's contentInset to fix a bug. for iOS 7.0.x - http://stackoverflow.com/questions/18966675/uitextview-in-ios7-clips-the-last-line-of-text-string Default is YES.
// */
//- (void)testTextView {
//
//}
Expand Down
4 changes: 2 additions & 2 deletions IQKeyboardManager.podspec.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "IQKeyboardManager",
"version": "4.0.1",
"version": "4.0.2",
"source": {
"git": "https://github.com/hackiftekhar/IQKeyboardManager.git",
"tag": "v4.0.1"
"tag": "v4.0.2"
},
"summary": "Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView.",
"homepage": "https://github.com/hackiftekhar/IQKeyboardManager",
Expand Down
4 changes: 2 additions & 2 deletions IQKeyboardManager/Categories/IQNSArray+Sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
/**
Returns the array by sorting the UIView's by their tag property.
*/
- (nonnull NSArray*)sortedArrayByTag;
@property (nonatomic, readonly, copy) NSArray * _Nonnull sortedArrayByTag;

/**
Returns the array by sorting the UIView's by their tag property.
*/
- (nonnull NSArray*)sortedArrayByPosition;
@property (nonatomic, readonly, copy) NSArray * _Nonnull sortedArrayByPosition;

@end
2 changes: 1 addition & 1 deletion IQKeyboardManager/Categories/IQUIView+Hierarchy.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ +(void)initialize

-(void)_setIsAskingCanBecomeFirstResponder:(BOOL)isAskingCanBecomeFirstResponder
{
objc_setAssociatedObject(self, @selector(isAskingCanBecomeFirstResponder), [NSNumber numberWithBool:isAskingCanBecomeFirstResponder], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(self, @selector(isAskingCanBecomeFirstResponder), @(isAskingCanBecomeFirstResponder), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

-(BOOL)isAskingCanBecomeFirstResponder
Expand Down
5 changes: 0 additions & 5 deletions IQKeyboardManager/IQKeyboardManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ extern NSInteger const kIQPreviousNextButtonToolbarTag;
*/
@property(nonatomic, assign) BOOL canAdjustTextView;

/**
Adjust textView's contentInset to fix a bug. for iOS 7.0.x - http://stackoverflow.com/questions/18966675/uitextview-in-ios7-clips-the-last-line-of-text-string Default is YES.
*/
@property(nonatomic, assign) BOOL shouldFixTextViewClip;

///---------------------------------------
/// @name UIKeyboard appearance overriding
///---------------------------------------
Expand Down
50 changes: 10 additions & 40 deletions IQKeyboardManager/IQKeyboardManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ @implementation IQKeyboardManager
//TextView handling
@synthesize canAdjustTextView = _canAdjustTextView;

@synthesize shouldFixTextViewClip = _shouldFixTextViewClip;

//Resign handling
@synthesize shouldResignOnTouchOutside = _shouldResignOnTouchOutside;

Expand Down Expand Up @@ -203,8 +201,6 @@ -(instancetype)init
[self addTextFieldViewDidBeginEditingNotificationName:UITextViewTextDidBeginEditingNotification
didEndEditingNotificationName:UITextViewTextDidEndEditingNotification];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldViewDidChange:) name:UITextViewTextDidChangeNotification object:nil];

// Registering for orientation changes notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willChangeStatusBarOrientation:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];

Expand Down Expand Up @@ -243,14 +239,13 @@ -(instancetype)init
strongSelf.enabledTouchResignedClasses = [[NSMutableSet alloc] init];

[self setShouldToolbarUsesTextFieldTintColor:NO];
[self setShouldFixTextViewClip:YES];
});
}
return self;
}

/* Automatically called from the `+(void)load` method. */
+ (instancetype)sharedManager
+ (IQKeyboardManager*)sharedManager
{
//Singleton instance
static IQKeyboardManager *kbManager;
Expand Down Expand Up @@ -947,7 +942,7 @@ -(void)keyboardWillShow:(NSNotification*)aNotification
if (_shouldAdoptDefaultKeyboardAnimation)
{
// Getting keyboard animation.
_animationCurve = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
_animationCurve = [[aNotification userInfo][UIKeyboardAnimationCurveUserInfoKey] integerValue];
_animationCurve = _animationCurve<<16;
}
else
Expand All @@ -956,15 +951,15 @@ -(void)keyboardWillShow:(NSNotification*)aNotification
}

// Getting keyboard animation duration
CGFloat duration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
CGFloat duration = [[aNotification userInfo][UIKeyboardAnimationDurationUserInfoKey] floatValue];

//Saving animation duration
if (duration != 0.0) _animationDuration = duration;

CGSize oldKBSize = _kbSize;

// Getting UIKeyboardSize.
CGRect kbFrame = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect kbFrame = [[aNotification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue];

CGRect screenSize = [[UIScreen mainScreen] bounds];

Expand Down Expand Up @@ -1013,7 +1008,7 @@ - (void)keyboardWillHide:(NSNotification*)aNotification
_isKeyboardShowing = NO;

// Getting keyboard animation duration
CGFloat aDuration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
CGFloat aDuration = [[aNotification userInfo][UIKeyboardAnimationDurationUserInfoKey] floatValue];
if (aDuration!= 0.0f)
{
_animationDuration = aDuration;
Expand Down Expand Up @@ -1275,31 +1270,6 @@ -(void)textFieldViewDidEndEditing:(NSNotification*)notification
_IQShowLog([NSString stringWithFormat:@"****** %@ ended ******",NSStringFromSelector(_cmd)]);
}

/** UITextViewTextDidChangeNotificationBug, fix for iOS 7.0.x - http://stackoverflow.com/questions/18966675/uitextview-in-ios7-clips-the-last-line-of-text-string */
-(void)textFieldViewDidChange:(NSNotification*)notification // (Bug ID: #18)
{
if (_shouldFixTextViewClip == YES && _enable == YES)
{
UITextView *textView = (UITextView *)notification.object;
CGRect line = [textView caretRectForPosition: textView.selectedTextRange.start];
CGFloat overflow = CGRectGetMaxY(line) - (textView.contentOffset.y + CGRectGetHeight(textView.bounds) - textView.contentInset.bottom - textView.contentInset.top);

//Added overflow conditions (Bug ID: 95)
if ( overflow > 0 && overflow < FLT_MAX)
{
// We are at the bottom of the visible text and introduced a line feed, scroll down (iOS 7 does not do it)
// Scroll caret to visible area
CGPoint offset = textView.contentOffset;
offset.y += overflow + 7; // leave 7 pixels margin

// Cannot animate with setContentOffset:animated: or caret will not appear
[UIView animateWithDuration:_animationDuration delay:0 options:(_animationCurve|UIViewAnimationOptionBeginFromCurrentState) animations:^{
[textView setContentOffset:offset];
} completion:NULL];
}
}
}

#pragma mark - UIInterfaceOrientation Change notification methods
/** UIApplicationWillChangeStatusBarOrientationNotification. Need to set the textView to it's original position. If any frame changes made. (Bug ID: #92)*/
- (void)willChangeStatusBarOrientation:(NSNotification*)aNotification
Expand Down Expand Up @@ -1433,7 +1403,7 @@ -(BOOL)goPrevious
//If it is not first textField. then it's previous object becomeFirstResponder.
if (index != NSNotFound && index > 0)
{
UITextField *nextTextField = [textFields objectAtIndex:index-1];
UITextField *nextTextField = textFields[index-1];

// Retaining textFieldView
UIView *textFieldRetain = _textFieldView;
Expand Down Expand Up @@ -1469,7 +1439,7 @@ -(BOOL)goNext
//If it is not last textField. then it's next object becomeFirstResponder.
if (index != NSNotFound && index < textFields.count-1)
{
UITextField *nextTextField = [textFields objectAtIndex:index+1];
UITextField *nextTextField = textFields[index+1];

// Retaining textFieldView
UIView *textFieldRetain = _textFieldView;
Expand Down Expand Up @@ -1555,7 +1525,7 @@ -(void)addToolbarIfRequired
UITextField *textField = nil;

if ([siblings count])
textField = [siblings objectAtIndex:0]; //Not using firstObject method because iOS5 doesn't not support 'firstObject' method.
textField = siblings[0];

//Either there is no inputAccessoryView or if accessoryView is not appropriate for current situation(There is Previous/Next/Done toolbar).
//setInputAccessoryView: check (Bug ID: #307)
Expand Down Expand Up @@ -1731,7 +1701,7 @@ -(void)addToolbarIfRequired

//In case of UITableView (Special), the next/previous buttons has to be refreshed everytime. (Bug ID: #56)
// If firstTextField, then previous should not be enabled.
if ([siblings objectAtIndex:0] == textField)
if (siblings[0] == textField)
{
[textField setEnablePrevious:NO next:YES];
}
Expand Down Expand Up @@ -1777,7 +1747,7 @@ - (void)reloadInputViews
for (UITextField *textField in siblings)
{
// If firstTextField, then previous should not be enabled.
if ([siblings objectAtIndex:0] == textField)
if (siblings[0] == textField)
{
if (siblings.count == 1)
{
Expand Down
Loading

0 comments on commit 2d27f52

Please sign in to comment.