Coder Social home page Coder Social logo

ios-autocomplete's Introduction

AutoCompletion

Description

A framework which provides text field suggestions as a dropdown list. It is available with iOS 8 and later, Objective-C or Swift.

Project Rationale

The purpose of this framework is to provide a simple, yet very useful feature - autocomplete textfield. IOS autocomplete is an iOS module that behaves like a normal text field with the added functionality that it provides suggestions to the user in a dropdown.

Installation

Add the "AutoCompletion.framework" to your project. Make sure the framework is added to 'Embedded Binaries' list from the General Tab of the Project Settings.

Usage

1. Import AutoCompletion framework. Objective-C

@import AutoCompletion; 

Swift

import AutoCompletion 

2. Add an autocompletion instance inside a view:

2.1 Drag and drop a UITextField instance in Interface Builder.

2.2 Change it's class to AutoCompletionTextField.

2.3 Aditionally, you can customize the text field from Interface Builder.

2.4 Create a reference of the AutoCompletionTextField.



3. Set the suggestionsResultDataSource. The data source needs to conform to the AutoCompletionTextFieldDataSource protocol:

Swift

class AutoCompletionDataSource: NSObject, AutoCompletionTextFieldDataSource {
    func fetchSuggestionsForIncompleteString(incompleteString: String!, withCompletionBlock completion: FetchCompletionBlock!) {
        ...code...
    }
}

...

autoCompletionTextField.suggestionsResultDataSource = AutoCompletionDataSource()

Objective-C

@interface AutoCompletionDataSource: NSObject <AutoCompletionTextFieldDataSource>
@end

@implementation AutoCompletionDataSource
- (void)fetchSuggestionsForIncompleteString:(NSString*)incompleteString
                        withCompletionBlock:(FetchCompletionBlock)completion {
    ...code...
}
@end

...

autoCompletionTextField.suggestionsResultDataSource = [AutoCompletionDataSource new];

4. Optionally, you can set the suggestionsResultDelegate in order to handle the suggestion selection.

Swift

class ViewController: UIViewController, AutoCompletionTextFieldDelegate {    
    @IBOutlet weak var autoCompletionTextField: AutoCompletionTextField!

    override func viewDidLoad() {
        super.viewDidLoad()
        autoCompletionTextField.suggestionsResultDelegate = self
    }
    
    // MARK: Delegate
    
    func textField(textField: AutoCompletionTextField!, didSelectItem selectedItem: AnyObject!) {
		...code...
    }
}

Objective-C

@interface ViewController: UIViewController <AutoCompletionTextFieldDelegate>

@property (weak, nonatomic) IBOutlet AutoCompletionTextField *autoCompletionTextField;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.autoCompletionTextField.suggestionsResultDelegate = self;
}

#pragma mark - Delegate

- (void)textField:(AutoCompletionTextField*)textField didSelectItem:(id)selectedItem {
	...code...
}

5. Also, you can set the animationDelegate in order to provide a custom animation to displaying of the results. It needs to conform to the AutoCompletionAnimator protocol:

Swift

class AutoCompletionAnimation: NSObject, AutoCompletionAnimator {
    
    func showSuggestionsForTextField(textField: AutoCompletionTextField!, table: UITableView!, numberOfItems count: Int) {
    	...code...    
   	 }
    
    func hideSuggestionsForTextField(textField: AutoCompletionTextField!, table: UITableView!) {
    	...code...
    }
}

...

autoCompletionTextField.animationDelegate = AutoCompletionAnimation()

Objective-C

@interface AutoCompletionAnimation: NSObject<AutoCompletionAnimator>
@end

@implementation AutoCompletionAnimation

- (void)showSuggestionsForTextField:(AutoCompletionTextField*)textField
                              table:(UITableView*)table
                      numberOfItems:(NSInteger)count {
	...code...
}
- (void)hideSuggestionsForTextField:(UITextField*)textField
                              table:(UITableView*)table {
	...code...
}

@end

...

autoCompletionTextField.animationDelegate = [AutoCompletionAnimation new];

In the demo project you're able to see a workable example for AutoCompletion where the suggestions results come from three different scenarios: CoreData, JSON, and API.

Known issues

If written text and suggestion have different letter case or if written text starts shifting to left, the suggestion doesn't overlap correctly the written text.

License

AutoCompletion is released under MIT license. See LICENSE for details.

About this project

![3Pillar Global] (http://www.3pillarglobal.com/wp-content/themes/base/library/images/logo_3pg.png)

AutoCompletion is developed and maintained by 3Pillar Global.

ios-autocomplete's People

Contributors

dmacra avatar flaviu88 avatar geluard avatar mmx1 avatar rcristian avatar valentinaiancu3pg avatar

Watchers

 avatar  avatar

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.