Code Monkey home page Code Monkey logo

bskeyboardcontrols's Introduction

Introduction

BSKeyboardControls makes it easy to add an input accessory view above the keyboard which allows to go to the previous and next text fields as well as close the keyboard. Much like it is seen in Safari on iOS.

  • iPhone and iPad compatible
  • Requires iOS 5+
  • Uses ARC

Installation

The easiest way to use BSKeyboardControls is to copy the files in BSKeyboardControls/ into your Xcode project.

  1. In Finder, navigate to your BSKeyboardControls directory
  2. Drag the complete directory into Xcode

OR

  1. Add pod 'BSKeyboardControls', '~> 2.2' to your Podfile

Usage

Wherever you want to use BSKeyboardControls import BSKeyboardControls.h like this:

#import "BSKeyboardControls.h"

Now you will have to set up BSKeyboardControls. This is done in five easy steps:

  1. Initialize the keyboard controls
  2. Set the delegate of the keyboard controls
  3. Add all the fields to the keyboard controls (The order of the fields is important)
  4. Set the delegate of all the text fields

Below is an example on how to setup the keyboard controls. The below example assumes the the text fields and the text views have had their delegate set in Interface Builder.

NSArray *fields = @[ self.textFieldUsername, self.textFieldPassword,
                     self.textFieldRepeatedPassword, self.textViewAbout,
                     self.textFieldFavoriteFood, self.textFieldFavoriteMovie,
                     self.textFieldFavoriteBook, self.textViewNotes];

[self setKeyboardControls:[[BSKeyboardControls alloc] initWithFields:fields]];
[self.keyboardControls setDelegate:self];

Next you will have to set up the delegation methods. BSKeyboardControls requires three delegates: BSKeyboardControlsDelegate, UITextFieldDelegate and UITextViewDelegate.

First you want to close the keyboard if the user presses the "Done button".

- (void)keyboardControlsDonePressed:(BSKeyboardControls *)keyboardControls
{
	[keyboardControls.activeField resignFirstResponder];
}

Next you want the view to scroll whenever a field is selected. There are a lot of ways to do this and you may have to tweak this.

- (void)keyboardControls:(BSKeyboardControls *)keyboardControls selectedField:(UIView *)field inDirection:(BSKeyboardControlsDirection)direction
{
	UIView *view = keyboardControls.activeField.superview.superview;
    [self.tableView scrollRectToVisible:view.frame animated:YES];
}

This is all there is for the BSKeyboardControlsDelegate. Now you want to set up the UITextFieldDelegate. The only method required is - (void)textFieldDidBeginEditing:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
	[self.keyboardControls setActiveField:textField];
}

Next you set up the - (void)textViewDidBeginEditing: method of the UITextViewDelegate. This is similar to the UITextFieldDelegate.

- (void)textViewDidBeginEditing:(UITextView *)textView
{
	[self.keyboardControls setActiveField:textView];
}

Now you are ready to use BSKeyboardControls. For more information on how to use BSKeyboardControls, please see Example.xcodeproj.

bskeyboardcontrols's People

Contributors

azu avatar ferbass avatar gantman avatar hesenrre avatar kasimov avatar kayleya avatar kylef avatar mdsilber avatar msamitas avatar rm1210 avatar satgi avatar simonbs avatar spipau avatar squarefrog avatar stevemoser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bskeyboardcontrols's Issues

A question about using BSKeyboardControls with a UIScrollView

Hi! Hope it's okay that I ask a question here.

Would it be possible to get an example app or a tutorial of how to use BSKeyboardControls with a UIScrollView on both iOS 6 and 7. I have tried but not succeeded and I don't really know how to implement this with my scroll view.

iOS7 Prev Next UISegment looks strange

using UISegment for the Prev and Next buttons suited iOS6 but i feels it looks a bit strange for iOS7. i.e, iOS7's UISegment has a flat blue outline which ideally should not be there.

If doesn't look like we can easily make the Segment Outline disappear then perhaps we could make it two UIButtons (One for Prev, one for Next), instead?

iOS 10 Arrows Suggestion

As you may already have seen, the default iOS 10 keyboard controls have changed from Left / Right arrows to Up / Down. I have made the following easy fix to my app and you may want to do so:
Changing current UIBarButtonSystemItems in BSKeyboardControls.m from 105/106 to 103/104.
That's all :)

Doesn't work with Swift 3.0

Hi simonbs,

I am using BSKeyboardControls in my swift project.

After i have converted my swift 2.3 to 3 and BSKeyboardControls is stop working.

Any idea ? Should i need to change anything?

keyboard, upon close doesn't move view to original position

Hi. First off, thanks to Simonbs for writing this awesome control!

I'm not sure if this is an issue or just my ignorance with ios (I'm a newbie).

I have a tableview that has a textfield which gets pushed up properly when the keyboard appears however, when the keyboard is dismissed, the tableview is not put back where it was originally. It looks like the offset is the height of the status bar.

I know ios7 introduced sliding under statusbar/navbar and I do have "extend edges..under top bars unchecked so I'm not sure what's causing this. My tableview/view implementation is cookie cutter.

Thanks.

Disable Done Button

Is there any way to disable the Done button when the text field is empty?

Thanks.

Keyboard Not Showing running against Xcode 6.0.1

Having upgrading my projects to use BSKeyboardControls to support the new Xcode, iOS8, iPhones, etc, screens that used this control do not display the keyboard. Instead, just the toolbar shows at the bottom of the view.

In an effort to make sure it was not my code, I download the latest Example from here on Github. The example is doing the same, See attached image.

Wondering if anyone else is using this control and if so, how they got around this.

example1

example2

This behavior was found on almost all of the targets for the simulator (iPhone 4s, iPhone 5s, iPhone 6 and iPhone 6 Plus).

It does work as expected only on the iPhone 5 - as in this screenshot.

example3

Cocoapod asks for username and password

When I'm trying to install BSKeyboardControls using cocoapods from terminal it asks for username and password and below is the error:

[!] git clone --mirror "https://github.com/SimonBS/BSKeyboardControls.git" "/Users/myname/Library/Caches/CocoaPods/Git/ef1f57d03d03b34921a7b0db79ab090d4b2c1fab"

Cloning into bare repository /Users/myname/Library/Caches/CocoaPods/Git/ef1f57d03d03b34921a7b0db79ab090d4b2c1fab...
fatal: Authentication failed

Please help.

CocoaPods Podspec

Please can you update the podspec on cocoapods to version 2.3.

At the moment we have to define it in our podfile like this...

pod 'BSKeyboardControls', :git => 'https://github.com/simonbs/BSKeyboardControls.git' 

It would be great if we could just use it without specifying the github url like this:

pod 'BSKeyboardControls', '~> 2.3'

Thanks

_fields retain

  • (void)setFields:(NSArray *)fields
    {
    if (fields != _fields)
    {
    for (UIView *field in fields)
    {
    if ([field isKindOfClass:[UITextField class]])
    {
    [(UITextField *)field setInputAccessoryView:self];
    }
    else if ([field isKindOfClass:[UITextView class]])
    {
    [(UITextView *)field setInputAccessoryView:self];
    }
    }

    _fields = fields; //Why isn't "_fields = [fields retain];"?
    

    }
    }

Add textfields dynamically

Thanks for your great work!

How do I add textfields to the array when I create the textfields dynamically? I do the initialization and then in the "cellForRowAtIndexPath" method I do:

        // create text field
        UITextField *txt = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, tableView.frame.size.width-40, 21)];
        txt.backgroundColor = [UIColor clearColor];
        txt.tag = indexPath.section;
        txt.keyboardType = UIKeyboardTypeDefault;            

        // add it to keyboardcontrols
        [(NSMutableArray *)self.keyboardControls.textFields addObject:txt];

        txt.inputAccessoryView = self.keyboardControls;
        txt.delegate = self;
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:UITextFieldTextDidChangeNotification object:txt];

        [cell.contentView addSubview:txt];

I get a (null) if I do an NSLog of self.keyboardControls.textFields

Thanks Again!

Dynamic Textfields

I am facing one problem and its a main issue for me i have a tableview and create single cell which contain 1 textfield now i create numbero of rows to 10 and create 10 cells of textfield how do i manage those because you create textfields as iboutlet and set into it in array initially but i dont have textfields initially

How to use BSKeyboardControls with UITableView (in Swift)?

I am successfully using BSKeyboardControls with a fixed number of defined fields...works great!!!

I have another UIViewController containing only a UITableView with a dynamic cell prototype containing a single text field. The number of rows in the table is known, but cells are not all allocated at once. (They are "dequeued" such that only visible cells are allocated.) I want to be able to use Previous and Next to go through all of the textfields in the table one row at a time, not just the visible textfields/rows.

How can I configure BSKeyboardControls to do this? (Advice in Swift would be appreciated.)

Thanks.

Textfields not being released from memory

Hi!
I think that "fields" array property of BSKeyboardControls class should have weak reference, otherwise textfields are not being released from memory.
See attached screenshot.

bskeyboardcontrolsdelegate

Done button causing fatal error due to unexpected nil?

Im using swift 4.1 and xcode 9. I followed each of your steps but changed the obj c to swift. When I press the done button in my app, it causes a fatal error: unexpected nil. Also it does not scroll or change fields when i click the forward or prev arrows? Any ideas on what the problem is? I can post my code if necessary.

Issue with Custom Text Field Backgrounds (and iOS7 update needed)

I'm writing a form app that uses a lot of Text fields just like the example app. However, my designer wishes to have a custom Text Field Border style and color;

textField.layer.cornerRadius=8.0f;
textField.layer.masksToBounds=YES;
[[textField layer] setBorderColor:[[UIColor colorWithRed:171.0/255.0 green:171.0/255.0 blue:171.0/255.0 alpha:1.0] CGColor]];
textField.layer.borderWidth= 1.0f;

This is so when the user is currently editing a Text Field the field can turn a Blue color often seen on a lot of websites lately. The idea is that only the field being edited turns Blue. Using the left and right arrows on the BSKeyboardControls works fine, and the fields change correctly. However, when the user does NOT use the left / right arrows and instead manually jumps fields (by manually tapping the field), the field stays the same blue color instead of reverting back to the Gray Color. The following code (found in the TextFieldShouldBeginEditing command line) is what causes this:

[self.keyboardControls setActiveField:textField];

Removing this sequence lets the manual field jump change colors correctly, but naturally it removes the previous / next functionality of the Control Bar.

Any chance you can issue a fix for this so that even if the user manually jumps to different fields they will change color appropriately?

Just as an FYI, XCode gives me 2 warnings on this line contained in the .m file:

[self.segmentedControl setSegmentedControlStyle:UISegmentedControlStyleBar];

setSegmentedControlStyle and UISegmentedControlStyleBar are both depreciated as of iOS7. Just wanted to give you a heads up in an otherwise very handy and excellently built project!

doesn't scroll if textview has focus

Great work on this but I thought I'd mention on the iphone that the view doesn't scroll if the focus is in a textview. Works great for textfield. I haven't tested other types of controls yet.

iOS8 word-completion keyboard

Noticing that if you pull up the iOS 8 style word completion view you are unable to dismiss it.Probably covering it with he BSKeyboardControls?

Issue with setBarStyle

Right now by default the tools bar is set to use UIBarStyleBlackTranslucent, but _barStyle isn't updated to UIBarStyleBlackTranslucent. So when you call setBarStyle:UIBarStyleDefault, it actually doesn't do anything because it's wrapped in if (barStyle != _barStyle).

There are many ways to fix the problem: use UIBarStyleDefault, or don't check if (barStyle != _barStyle) in setBayStyle call, or initialize _barStyle to UIBarStyleBlackTranslucent.

Update Cocoapods with master

First off, I want to say great library - it is super useful and helpful and looks great.

It looks like the Cocoapods version is older than master. Personally, I have to manually include the source files in my project because I want to take advantage of the iOS 7 arrows (instead of the Prev/Next text).

Is there an ETA when Cocoapods will be updated? Thanks so much!

Previous button bug with pickerView

I have made a table with 6 textFields, but the last 2 are custom to show pickerView and a datePickerView instead of the regular keyboard.

The 'next' button of the toolBar, take me through all the 6 fields, but when I try to go back to the previous fields I can only go back 4 fields.

Any idea why this is happening?

directionPressed never called

- (void)keyboardControls:(BSKeyboardControls *)keyboardControls directionPressed:(BSKeyboardControlsDirection)direction is never called, is it? In the example it isn't called as well...

question about done button

Hi,
Why did you used

    [self setDoneButton:[[UIBarButtonItem alloc] initWithTitle:NSLocalizedStringFromTable(@"Done", @"BSKeyboardControls", @"Done button title.")
                                                         style:UIBarButtonItemStyleDone
                                                        target:self
                                                        action:@selector(doneButtonPressed:)]];

instead of

[self setDoneButton:[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)]];

Custom Background color

Is there a way to set custom background color?

I tried
self.keyboardControls.backgroundColor = [UIColor blackColor];
but nothing happened

Not Properly Scrolling Anymore in iOS7

When test my app for the upcoming iOS7, I noticed that the scrolling to the active text field no longer works.

I tried just testing the supplied Example.xcodeproj to ensure it was not something funky I was doing.

The Example project worked fine when running in the iOS6 simulator. I can navigate to the all the fields back and forth, using the next and previous buttons. The view is scrolled and focused properly.

However, when I run this on the iOS7 simulator, I can navigate to the first few fields fine in the Example project. When I get to the "Your favorite food?" field, pressing the "Next" button, scrolls the view to the top - showing Username, Password, etc... but cursor is in "Your favorite movie?" field behind the keyboard. In my app, the same thing is occurring.

I believe the problem is in the scrollRectToVisible and the iOS7 keyboard. I know this is probably not a problem with this great control - but it will "break" the Example once iOS7 is released if there is not a fix with Apple or another workaround.

Done button does not work if text field is off the view

"Done" button does not work if text field is off the view. Steps to replicate this bug:

Open Example project on either simulator or device. Tap on username text field. Keep pressing next until it is greyed out. Now tap done - nothing happens.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.