├── .gitignore ├── LICENSE.md ├── README.md ├── Screenshots └── screenshot.png ├── WUTextSuggestion.podspec ├── WUTextSuggestion ├── WUTextSuggestionController.h ├── WUTextSuggestionController.m ├── WUTextSuggestionDisplayController.h └── WUTextSuggestionDisplayController.m └── WUTextSuggestionDemo ├── WUTextSuggestionDemo.xcodeproj └── project.pbxproj └── WUTextSuggestionDemo ├── AppDelegate.h ├── AppDelegate.m ├── Default-568h@2x.png ├── Default.png ├── Default@2x.png ├── DemoViewController.h ├── DemoViewController.m ├── WUTextSuggestionDemo-Info.plist ├── WUTextSuggestionDemo-Prefix.pch ├── en.lproj ├── InfoPlist.strings └── MainStoryboard.storyboard └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 YuAo. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #WUTextSuggestion 2 | 3 | A text suggestion toolkit for iOS. 4 | 5 | ![ScreenShot](Screenshots/screenshot.png) 6 | 7 | _Download and run the demo project to see it in action._ 8 | 9 | ##What can it do? 10 | 11 | `WUTextSuggestion` is still early in development, it currently supports **@ (at)** and **\# (hashtag, twitter style)** suggestions for `UITextView`. 12 | 13 | ------ 14 | 15 | `WUTextSuggestion` aims to be a full featured text suggestion toolkit for iOS. 16 | 17 | It can easily be integrated in your project with only couple lines of code. 18 | 19 | It allows you to load text suggestions asynchronously from a remote server. 20 | 21 | It is fully customizable. You can design your own text suggestion display controller to work with it. 22 | 23 | ##What's inside? 24 | 25 | `WUTextSuggestion` is consists of two parts. 26 | 27 | ####WUTextSuggestionController 28 | 29 | `WUTextSuggestionController` provides the text searching and checking function. It tells you when and how you should give your user text suggestions. 30 | 31 | ####WUTextSuggestionDisplayController 32 | 33 | `WUTextSuggestionDisplayController`, a text suggestion display controller based on `UIMenuController`. It asks it's `dataSource` for the text suggestions, and display them beautifully on the screen. 34 | 35 | ##Usage 36 | 37 | ### A. The simple way, use WUTextSuggestionDisplayController. 38 | 39 | Using `WUTextSuggestionDisplayController` to display text suggestions. 40 | 41 | 1. Setup. 42 | 43 | ``` 44 | //Create a WUTextSuggestionDisplayController and assign the dataSource. 45 | WUTextSuggestionDisplayController *suggestionDisplayController = [[WUTextSuggestionDisplayController alloc] init]; 46 | suggestionDisplayController.dataSource = self; 47 | 48 | //Create a WUTextSuggestionController with a textView and the suggestionDisplayController you just created. 49 | WUTextSuggestionController *suggestionController = [[WUTextSuggestionController alloc] initWithTextView:self.textView suggestionDisplayController:suggestionDisplayController]; 50 | 51 | //Set the suggestion type 52 | suggestionController.suggestionType = WUTextSuggestionTypeAt | WUTextSuggestionTypeHashTag; 53 | 54 | ``` 55 | 56 | 2. Provide the suggestions. 57 | 58 | You need to provide the text suggestions based on `suggestionType` and `suggestionQuery`. 59 | 60 | When a user typed `@na`, the `suggestionType` will be `WUTextSuggestionTypeAt`, and the `suggestionQuery` will be `na`. 61 | 62 | You need to wrap the suggestions in `WUTextSuggestionItem` objects, return an array of WUTextSuggestionItem. 63 | 64 | A `WUTextSuggestionItem` has a `title` and a `customActionBlock`. 65 | 66 | `title` is the suggesting text. 67 | 68 | `customActionBlock`, if assigned, will be executed after user tapped that text suggestion. 69 | 70 | ``` 71 | //WUTextSuggestionDisplayControllerDataSource 72 | 73 | - (NSArray *)textSuggestionDisplayController:(WUTextSuggestionDisplayController *)textSuggestionDisplayController suggestionDisplayItemsForSuggestionType:(WUTextSuggestionType)suggestionType query:(NSString *)suggestionQuery 74 | { 75 | //return an array of WUTextSuggestionItem. 76 | } 77 | 78 | ``` 79 | 80 | You can also chose to use `-textSuggestionDisplayController:suggestionDisplayItemsForSuggestionType:query:callback:` for async data loading. 81 | 82 | 3. Done. **There's a demo project `WUTextSuggestionDemo`**. 83 | 84 | ### B. Working with your custom text suggestion display controller. 85 | 86 | 1. You need to use `- initWithTextView:` to create an instance of `WUTextSuggestionController`. 87 | 88 | 2. The `textView` will hold a strong pointer to the `textSuggestionController` which can be acquired using `textSuggestionController` property of the `textView`. 89 | 90 | 3. Set the `suggestionType` property of the `textSuggestionController`. 91 | 92 | 4. Listen to the callback and present your custom text suggestion view. 93 | 94 | 95 | ``` 96 | //1. 97 | WUTextSuggestionController *suggestionController = [[WUTextSuggestionController alloc] initWithTextView:self.textView]; 98 | 99 | //3. 100 | suggestionController.suggestionType = WUTextSuggestionTypeAt | WUTextSuggestionTypeHashTag; 101 | 102 | //4. 103 | [suggestionController setShouldBeginSuggestingBlock:^{ 104 | //"@" or "#" detected. You should prepare your text suggestion view. 105 | }]; 106 | [suggestionController setShouldReloadSuggestionsBlock:^(WUTextSuggestionType type, NSString *query, NSRange range) { 107 | //User typed something after the "@" or "#", you should show your text suggestion view with suggestions. 108 | }]; 109 | [suggestionController setShouldEndSuggestingBlock:^{ 110 | //Suggesting end. You should hide your text suggestion view. 111 | }]; 112 | 113 | ``` 114 | 115 | ##Roadmap 116 | 117 | - UITextField support. 118 | 119 | ##Requirements 120 | 121 | - Automatic Reference Counting (ARC) 122 | - iOS 5.0+ 123 | - Xcode 4.5+ 124 | 125 | ##Contributing 126 | 127 | If you find a bug and know exactly how to fix it, please open a pull request. 128 | 129 | If you can't make the change yourself, please open an issue after making sure that one isn't already logged. 130 | 131 | ##License 132 | 133 | The MIT license, as aways. 134 | -------------------------------------------------------------------------------- /Screenshots/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuAo/WUTextSuggestion/3884f37e2028735ca738d3bc24952066b9b1cdb1/Screenshots/screenshot.png -------------------------------------------------------------------------------- /WUTextSuggestion.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "WUTextSuggestion" 3 | s.version = "0.2.0" 4 | s.summary = "A text suggestion toolkit for iOS." 5 | s.description = <<-DESC 6 | `WUTextSuggestion` aims to be a full featured text suggestion toolkit for iOS. 7 | 8 | It can easily be integrated in your project with only couple lines of code. 9 | 10 | It allows you to load text suggestions asynchronously from a remote server. 11 | 12 | It is fully customizable. You can design your own text suggestion display controller to work with it. 13 | DESC 14 | s.homepage = "https://github.com/YuAo/WUTextSuggestion" 15 | s.license = { :type => 'MIT', :file => 'LICENSE.md' } 16 | s.author = { "Yu Ao" => "me@imyuao.com" } 17 | s.platform = :ios, '6.0' 18 | s.source = { :git => "https://github.com/YuAo/WUTextSuggestion.git", :tag => "0.2.0" } 19 | s.source_files = 'WUTextSuggestion', 'WUTextSuggestion/**/*.{h,m}' 20 | s.frameworks = 'UIKit', 'Foundation' 21 | s.requires_arc = true 22 | end 23 | -------------------------------------------------------------------------------- /WUTextSuggestion/WUTextSuggestionController.h: -------------------------------------------------------------------------------- 1 | // 2 | // WUTextSuggestionControl.h 3 | // WeicoUI 4 | // 5 | // Created by YuAo on 5/8/13. 6 | // Copyright (c) 2013 微酷奥(北京)科技有限公司. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSUInteger, WUTextSuggestionType) { 12 | WUTextSuggestionTypeNone = 0, 13 | WUTextSuggestionTypeAt = 1 << 0, 14 | WUTextSuggestionTypeHashTag = 1 << 1 15 | }; 16 | 17 | @interface WUTextSuggestionController : NSObject 18 | 19 | @property (nonatomic) WUTextSuggestionType suggestionType; 20 | 21 | @property (nonatomic,copy) void (^shouldBeginSuggestingBlock)(void); 22 | @property (nonatomic,copy) void (^shouldReloadSuggestionsBlock)(WUTextSuggestionType suggestionType, NSString *suggestionQuery, NSRange suggestionRange); 23 | @property (nonatomic,copy) void (^shouldEndSuggestingBlock)(void); 24 | 25 | @property (nonatomic,weak,readonly) UITextView *textView; 26 | - (id)initWithTextView:(UITextView *)textView; 27 | 28 | @end 29 | 30 | 31 | @interface UITextView (WUTextSuggestionController) 32 | 33 | @property (nonatomic,strong) WUTextSuggestionController *textSuggestionController; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /WUTextSuggestion/WUTextSuggestionController.m: -------------------------------------------------------------------------------- 1 | // 2 | // WUTextSuggestionControl.m 3 | // WeicoUI 4 | // 5 | // Created by YuAo on 5/8/13. 6 | // Copyright (c) 2013 微酷奥(北京)科技有限公司. All rights reserved. 7 | // 8 | 9 | #import "WUTextSuggestionController.h" 10 | #import 11 | 12 | NSString * const WUTextSuggestionControllerTextInputSelectedTextRangePropertyKey = @"selectedTextRange"; 13 | NSString * const WUTextSuggestionControllerTextInputTextPropertyKey = @"text"; 14 | 15 | @interface WUTextSuggestionController () 16 | 17 | @property (nonatomic,weak,readwrite) UITextView *textView; 18 | 19 | @property (nonatomic,strong) NSRegularExpression *textCheckingRegularExpression; 20 | 21 | @property (nonatomic,readwrite,getter = isSuggesting) BOOL suggesting; 22 | @property (nonatomic,readwrite) NSRange suggestionRange; 23 | 24 | @property (nonatomic) BOOL observingSelectedTextRange; 25 | @property (nonatomic) BOOL observingTextInputText; 26 | 27 | @end 28 | 29 | @implementation WUTextSuggestionController 30 | 31 | - (id)initWithTextView:(UITextView *)textView { 32 | if (self = [super init]) { 33 | NSParameterAssert(textView); 34 | self.textView = textView; 35 | 36 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged) name:UITextViewTextDidChangeNotification object:self.textView]; 37 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textViewDidBeginEditing:) name:UITextViewTextDidBeginEditingNotification object:self.textView]; 38 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textViewDidEndEditing:) name:UITextViewTextDidEndEditingNotification object:self.textView]; 39 | 40 | self.textView.textSuggestionController = self; 41 | } 42 | return self; 43 | } 44 | 45 | - (void)dealloc { 46 | self.observingSelectedTextRange = NO; 47 | self.observingTextInputText = NO; 48 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 49 | } 50 | 51 | - (void)setSuggesting:(BOOL)suggesting { 52 | if (_suggesting != suggesting) { 53 | _suggesting = suggesting; 54 | if (suggesting) { 55 | if (self.shouldBeginSuggestingBlock) { 56 | self.shouldBeginSuggestingBlock(); 57 | } 58 | } else { 59 | if (self.shouldEndSuggestingBlock) { 60 | self.shouldEndSuggestingBlock(); 61 | } 62 | } 63 | } 64 | } 65 | 66 | - (void)setObservingSelectedTextRange:(BOOL)observingSelectedTextRange { 67 | if (_observingSelectedTextRange != observingSelectedTextRange) { 68 | _observingSelectedTextRange = observingSelectedTextRange; 69 | if (observingSelectedTextRange) { 70 | [self.textView addObserver:self forKeyPath:WUTextSuggestionControllerTextInputSelectedTextRangePropertyKey options:NSKeyValueObservingOptionNew context:NULL]; 71 | } else { 72 | [self.textView removeObserver:self forKeyPath:WUTextSuggestionControllerTextInputSelectedTextRangePropertyKey]; 73 | } 74 | } 75 | } 76 | 77 | - (void)setObservingTextInputText:(BOOL)observingTextInputText { 78 | if (_observingTextInputText != observingTextInputText) { 79 | _observingTextInputText = observingTextInputText; 80 | if (observingTextInputText) { 81 | [self.textView addObserver:self forKeyPath:WUTextSuggestionControllerTextInputTextPropertyKey options:NSKeyValueObservingOptionNew context:NULL]; 82 | } else { 83 | [self.textView removeObserver:self forKeyPath:WUTextSuggestionControllerTextInputTextPropertyKey]; 84 | } 85 | } 86 | } 87 | 88 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 89 | if (object == self.textView && ([keyPath isEqualToString:WUTextSuggestionControllerTextInputSelectedTextRangePropertyKey] || [keyPath isEqualToString:WUTextSuggestionControllerTextInputTextPropertyKey])) { 90 | [self textChanged]; 91 | } 92 | } 93 | 94 | - (void)textViewDidBeginEditing:(NSNotification *)notification { 95 | self.observingSelectedTextRange = YES; 96 | self.observingTextInputText = YES; 97 | [self textChanged]; 98 | } 99 | 100 | - (void)textViewDidEndEditing:(NSNotification *)notification { 101 | self.observingSelectedTextRange = NO; 102 | self.observingTextInputText = NO; 103 | self.suggesting = NO; 104 | } 105 | 106 | - (NSRegularExpression *)textCheckingRegularExpression { 107 | if (!_textCheckingRegularExpression) { 108 | _textCheckingRegularExpression = [NSRegularExpression regularExpressionWithPattern:@"[@#]([^\\s/::@#]?)+$?" options:NSRegularExpressionCaseInsensitive error:NULL]; 109 | } 110 | return _textCheckingRegularExpression; 111 | } 112 | 113 | - (void)textChanged { 114 | __block NSString *word = nil; 115 | __block NSRange range = NSMakeRange(NSNotFound, 0); 116 | 117 | [self.textCheckingRegularExpression enumerateMatchesInString:self.textView.text 118 | options:0 119 | range:NSMakeRange(0, self.textView.text.length) 120 | usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) 121 | { 122 | NSRange textSelectedRange = self.textView.selectedRange; 123 | if (textSelectedRange.location > result.range.location && textSelectedRange.location <= result.range.location + result.range.length) { 124 | word = [self.textView.text substringWithRange:result.range]; 125 | range = result.range; 126 | *stop = YES; 127 | } 128 | }]; 129 | 130 | if (word.length >= 1 && range.location != NSNotFound) { 131 | NSString *first = [word substringToIndex:1]; 132 | NSString *rest = [word substringFromIndex:1]; 133 | if ([first isEqualToString:@"@"] && (self.suggestionType & WUTextSuggestionTypeAt)) { 134 | self.suggesting = YES; 135 | self.suggestionRange = NSMakeRange(range.location + 1, range.length - 1); 136 | if (self.shouldReloadSuggestionsBlock) { 137 | self.shouldReloadSuggestionsBlock(WUTextSuggestionTypeAt,rest,self.suggestionRange); 138 | } 139 | } else if ([first isEqualToString:@"#"] && (self.suggestionType & WUTextSuggestionTypeHashTag)) { 140 | self.suggesting = YES; 141 | self.suggestionRange = NSMakeRange(range.location + 1, range.length - 1); 142 | if (self.shouldReloadSuggestionsBlock) { 143 | self.shouldReloadSuggestionsBlock(WUTextSuggestionTypeHashTag,rest,self.suggestionRange); 144 | } 145 | } else { 146 | self.suggestionRange = NSMakeRange(NSNotFound, 0); 147 | self.suggesting = NO; 148 | } 149 | } else { 150 | self.suggestionRange = NSMakeRange(NSNotFound, 0); 151 | self.suggesting = NO; 152 | } 153 | } 154 | 155 | @end 156 | 157 | NSString * const WUTextSuggestionControllerAssociationKey = @"WUTextSuggestionControllerAssociationKey"; 158 | 159 | @implementation UITextView (WUTextSuggestionController) 160 | 161 | - (void)setTextSuggestionController:(WUTextSuggestionController *)textSuggestionController { 162 | objc_setAssociatedObject(self, &WUTextSuggestionControllerAssociationKey, textSuggestionController, OBJC_ASSOCIATION_RETAIN); 163 | } 164 | 165 | - (WUTextSuggestionController *)textSuggestionController { 166 | return objc_getAssociatedObject(self, &WUTextSuggestionControllerAssociationKey); 167 | } 168 | 169 | @end 170 | 171 | -------------------------------------------------------------------------------- /WUTextSuggestion/WUTextSuggestionDisplayController.h: -------------------------------------------------------------------------------- 1 | // 2 | // WUTextSuggestionDisplayController.h 3 | // WUTextSuggestionController 4 | // 5 | // Created by YuAo on 5/11/13. 6 | // Copyright (c) 2013 YuAo. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "WUTextSuggestionController.h" 11 | 12 | @interface WUTextSuggestionDisplayItem : NSObject 13 | 14 | @property (nonatomic,copy,readonly) NSString *title; 15 | @property (nonatomic,copy) void (^customActionBlock)(WUTextSuggestionType suggestionType, NSString *suggestionQuery, NSRange suggestionRange); 16 | 17 | - (id)initWithTitle:(NSString *)title; 18 | 19 | @end 20 | 21 | 22 | @protocol WUTextSuggestionDisplayControllerDataSource; 23 | 24 | @interface WUTextSuggestionDisplayController : NSObject 25 | 26 | @property (nonatomic,weak) id dataSource; 27 | 28 | - (void)beginSuggestingForTextView:(UITextView *)textView; 29 | 30 | - (void)endSuggesting; 31 | 32 | - (void)reloadSuggestionsWithType:(WUTextSuggestionType)suggestionType query:(NSString *)suggestionQuery range:(NSRange)suggestionRange; 33 | 34 | @end 35 | 36 | 37 | @protocol WUTextSuggestionDisplayControllerDataSource 38 | 39 | @optional 40 | 41 | //Sync 42 | - (NSArray *)textSuggestionDisplayController:(WUTextSuggestionDisplayController *)textSuggestionDisplayController 43 | suggestionDisplayItemsForSuggestionType:(WUTextSuggestionType)suggestionType 44 | query:(NSString *)suggestionQuery; 45 | 46 | //Async 47 | - (void)textSuggestionDisplayController:(WUTextSuggestionDisplayController *)textSuggestionDisplayController 48 | suggestionDisplayItemsForSuggestionType:(WUTextSuggestionType)suggestionType 49 | query:(NSString *)suggestionQuery 50 | callback:(void (^)(NSArray *suggestionDisplayItems))gotSuggestionDisplayItemsBlock; 51 | 52 | @end 53 | 54 | 55 | @interface WUTextSuggestionController (WUTextSuggestionDisplayController) 56 | 57 | - (id)initWithTextView:(UITextView *)textView suggestionDisplayController:(WUTextSuggestionDisplayController *)suggestionDisplayController; 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /WUTextSuggestion/WUTextSuggestionDisplayController.m: -------------------------------------------------------------------------------- 1 | // 2 | // WUTextSuggestionDisplayController.m 3 | // WUTextSuggestionController 4 | // 5 | // Created by YuAo on 5/11/13. 6 | // Copyright (c) 2013 YuAo. All rights reserved. 7 | // 8 | 9 | #import "WUTextSuggestionDisplayController.h" 10 | #import 11 | 12 | NSString * const WUTextSuggestionDisplayControllerUIMenuControllerActionSelectorPrefix = @"textSuggestionDisplayControllerUIMenuControllerAction_"; 13 | 14 | NSString * const WUTextSuggestionDisplayItemAssociationKey = @"WUTextSuggestionDisplayItemAssociationKey"; 15 | 16 | @implementation WUTextSuggestionDisplayItem 17 | 18 | - (id)initWithTitle:(NSString *)title { 19 | if (self = [super init]) { 20 | _title = [title copy]; 21 | } 22 | return self; 23 | } 24 | 25 | @end 26 | 27 | @interface UIMenuItem (WUTextSuggestionDisplayController) 28 | 29 | @property (nonatomic,strong) WUTextSuggestionDisplayItem *textSuggestionDisplayItem; 30 | 31 | @end 32 | 33 | @implementation UIMenuItem (WUTextSuggestionDisplayController) 34 | 35 | - (void)setTextSuggestionDisplayItem:(WUTextSuggestionDisplayItem *)textSuggestionDisplayItem { 36 | objc_setAssociatedObject(self, &WUTextSuggestionDisplayItemAssociationKey, textSuggestionDisplayItem, OBJC_ASSOCIATION_RETAIN); 37 | } 38 | 39 | - (WUTextSuggestionDisplayItem *)textSuggestionDisplayItem { 40 | return objc_getAssociatedObject(self, &WUTextSuggestionDisplayItemAssociationKey); 41 | } 42 | 43 | @end 44 | 45 | static SEL WUTextSuggestionDisplayControllerUIMenuControllerActionSelectorForMenuItemWithTitle(NSString *title) { 46 | return NSSelectorFromString([NSString stringWithFormat:@"%@%@",WUTextSuggestionDisplayControllerUIMenuControllerActionSelectorPrefix,@(title.hash).stringValue]); 47 | } 48 | 49 | static BOOL WUTextSuggestionDisplayControllerUIMenuControllerActionSelectorMatchesMenuItemTitle(SEL selector, NSString *title) { 50 | NSString *hash = [NSStringFromSelector(selector) stringByReplacingOccurrencesOfString:WUTextSuggestionDisplayControllerUIMenuControllerActionSelectorPrefix withString:@""]; 51 | if ([hash isEqualToString:@(title.hash).stringValue]) { 52 | return YES; 53 | } else { 54 | return NO; 55 | } 56 | } 57 | 58 | @interface WUTextSuggestionDisplayController () 59 | @property (nonatomic,weak) UITextView *textView; 60 | @property (nonatomic) BOOL suggesting; 61 | 62 | @property (nonatomic,copy) NSString *suggestionQuery; 63 | @property (nonatomic) WUTextSuggestionType suggestionType; 64 | @property (nonatomic) NSRange suggestionRange; 65 | @end 66 | 67 | @implementation WUTextSuggestionDisplayController 68 | 69 | static WUTextSuggestionDisplayController __weak *_activeTextSuggestionDisplayController; 70 | 71 | + (WUTextSuggestionDisplayController *)activeTextSuggestionDisplayController { 72 | return _activeTextSuggestionDisplayController; 73 | } 74 | 75 | + (void)setActiveTextSuggestionDisplayController:(WUTextSuggestionDisplayController *)activeTextSuggestionDisplayController { 76 | _activeTextSuggestionDisplayController = activeTextSuggestionDisplayController; 77 | } 78 | 79 | - (void)beginSuggestingForTextView:(UITextView *)textView { 80 | self.textView = textView; 81 | self.suggesting = YES; 82 | } 83 | 84 | - (void)endSuggesting { 85 | [self.class setActiveTextSuggestionDisplayController:nil]; 86 | [UIMenuController sharedMenuController].menuItems = nil; 87 | self.suggesting = NO; 88 | self.textView = nil; 89 | } 90 | 91 | - (void)reloadSuggestionsWithType:(WUTextSuggestionType)suggestionType query:(NSString *)suggestionQuery range:(NSRange)suggestionRange { 92 | self.suggestionRange = suggestionRange; 93 | self.suggestionType = suggestionType; 94 | self.suggestionQuery = suggestionQuery; 95 | [self.class setActiveTextSuggestionDisplayController:nil]; 96 | [UIMenuController sharedMenuController].menuItems = nil; 97 | [NSObject cancelPreviousPerformRequestsWithTarget:self]; 98 | [self performSelector:@selector(delayShowSuggestionMenuController) withObject:nil afterDelay:0.2]; 99 | } 100 | 101 | - (void)delayShowSuggestionMenuController { 102 | void (^showMenuControllerWithSuggestionDisplayItems)(NSArray *suggestionDisplayItems) = ^(NSArray *suggestionItems){ 103 | if (self.suggesting && self.textView) { 104 | NSMutableArray *meunItems = [NSMutableArray array]; 105 | [suggestionItems enumerateObjectsUsingBlock:^(WUTextSuggestionDisplayItem *obj, NSUInteger idx, BOOL *stop) { 106 | UIMenuItem *item = [[UIMenuItem alloc] initWithTitle:obj.title action:WUTextSuggestionDisplayControllerUIMenuControllerActionSelectorForMenuItemWithTitle(obj.title)]; 107 | item.textSuggestionDisplayItem = obj; 108 | [meunItems addObject:item]; 109 | }]; 110 | if (meunItems.count) { 111 | CGRect caretRect = [self.textView caretRectForPosition:self.textView.selectedTextRange.start]; 112 | [self.class setActiveTextSuggestionDisplayController:self]; 113 | [UIMenuController sharedMenuController].menuItems = meunItems; 114 | [[UIMenuController sharedMenuController] setTargetRect:caretRect inView:self.textView]; 115 | [[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES]; 116 | } 117 | } 118 | }; 119 | if ([self.dataSource respondsToSelector:@selector(textSuggestionDisplayController:suggestionDisplayItemsForSuggestionType:query:callback:)]) { 120 | [self.dataSource textSuggestionDisplayController:self suggestionDisplayItemsForSuggestionType:self.suggestionType query:self.suggestionQuery callback:^(NSArray *suggestionDisplayItems) { 121 | dispatch_async(dispatch_get_main_queue(), ^{ 122 | showMenuControllerWithSuggestionDisplayItems(suggestionDisplayItems); 123 | }); 124 | }]; 125 | } else if ([self.dataSource respondsToSelector:@selector(textSuggestionDisplayController:suggestionDisplayItemsForSuggestionType:query:)]) { 126 | showMenuControllerWithSuggestionDisplayItems([self.dataSource textSuggestionDisplayController:self suggestionDisplayItemsForSuggestionType:self.suggestionType query:self.suggestionQuery]); 127 | } else { 128 | WUTextSuggestionDisplayItem *item = [[WUTextSuggestionDisplayItem alloc] initWithTitle:@"No DataSource Provided"]; 129 | showMenuControllerWithSuggestionDisplayItems(@[item]); 130 | } 131 | } 132 | 133 | - (void)textSuggestionDisplayItemTapped:(WUTextSuggestionDisplayItem *)item { 134 | if (item.customActionBlock) { 135 | item.customActionBlock(self.suggestionType,self.suggestionQuery,self.suggestionRange); 136 | } else { 137 | NSRange suggestionRange = self.suggestionRange; 138 | NSString *suggestionString = item.title; 139 | NSString *insertString = [suggestionString stringByAppendingString:@" "]; 140 | if (self.textView.text.length > suggestionRange.location + suggestionRange.length) { 141 | if ([[self.textView.text substringWithRange:NSMakeRange(suggestionRange.location, suggestionRange.length + 1)] hasSuffix:@" "]) { 142 | insertString = suggestionString; 143 | } 144 | } 145 | self.textView.text = [self.textView.text stringByReplacingCharactersInRange:suggestionRange withString:insertString]; 146 | } 147 | } 148 | 149 | @end 150 | 151 | @implementation WUTextSuggestionController (WUTextSuggestionDisplayController) 152 | 153 | - (id)initWithTextView:(UITextView *)textView suggestionDisplayController:(WUTextSuggestionDisplayController *)suggestionDisplayController { 154 | if (self = [self initWithTextView:textView]) { 155 | __weak __typeof(&*self)weakSelf = self; 156 | [self setShouldBeginSuggestingBlock:^{ 157 | [suggestionDisplayController beginSuggestingForTextView:weakSelf.textView]; 158 | }]; 159 | [self setShouldReloadSuggestionsBlock:^(WUTextSuggestionType type, NSString *query, NSRange range) { 160 | [suggestionDisplayController reloadSuggestionsWithType:type query:query range:range]; 161 | }]; 162 | [self setShouldEndSuggestingBlock:^{ 163 | [suggestionDisplayController endSuggesting]; 164 | }]; 165 | } 166 | return self; 167 | } 168 | 169 | @end 170 | 171 | static void class_swizzleSelector(Class class, SEL originalSelector, SEL newSelector) 172 | { 173 | Method origMethod = class_getInstanceMethod(class, originalSelector); 174 | Method newMethod = class_getInstanceMethod(class, newSelector); 175 | if(class_addMethod(class, originalSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) { 176 | class_replaceMethod(class, newSelector, method_getImplementation(origMethod), method_getTypeEncoding(origMethod)); 177 | } else { 178 | method_exchangeImplementations(origMethod, newMethod); 179 | } 180 | } 181 | 182 | @interface UITextView (WUTextSuggestionDisplayController) 183 | 184 | @end 185 | 186 | @implementation UITextView (WUTextSuggestionDisplayController) 187 | 188 | + (void)load { 189 | static dispatch_once_t onceToken; 190 | dispatch_once(&onceToken, ^{ 191 | @autoreleasepool { 192 | class_swizzleSelector(self, @selector(canPerformAction:withSender:), @selector(textView_WUTextSuggestionDisplayController_canPerformAction:withSender:)); 193 | class_swizzleSelector(self, @selector(methodSignatureForSelector:), @selector(textView_WUTextSuggestionDisplayController_methodSignatureForSelector:)); 194 | class_swizzleSelector(self, @selector(forwardInvocation:), @selector(textView_WUTextSuggestionDisplayController_forwardInvocation:)); 195 | } 196 | }); 197 | } 198 | 199 | - (BOOL)textView_WUTextSuggestionDisplayController_canPerformAction:(SEL)action withSender:(id)sender { 200 | if ([NSStringFromSelector(action) hasPrefix:WUTextSuggestionDisplayControllerUIMenuControllerActionSelectorPrefix]) { 201 | if ([WUTextSuggestionDisplayController activeTextSuggestionDisplayController].suggesting) { 202 | return YES; 203 | } else { 204 | return NO; 205 | } 206 | } 207 | if ([WUTextSuggestionDisplayController activeTextSuggestionDisplayController].suggesting) { 208 | if (action == @selector(paste:) || action == @selector(selectAll:) || action == @selector(select:)) { 209 | return NO; 210 | } 211 | } 212 | return [self textView_WUTextSuggestionDisplayController_canPerformAction:action withSender:sender]; 213 | } 214 | 215 | - (void)textSuggestionDisplayControllerUIMenuControllerAction_xxxx { 216 | //A Placeholder Method 217 | return; 218 | } 219 | 220 | - (NSMethodSignature *)textView_WUTextSuggestionDisplayController_methodSignatureForSelector:(SEL)aSelector { 221 | if ([NSStringFromSelector(aSelector) hasPrefix:WUTextSuggestionDisplayControllerUIMenuControllerActionSelectorPrefix]) { 222 | return [self textView_WUTextSuggestionDisplayController_methodSignatureForSelector:@selector(textSuggestionDisplayControllerUIMenuControllerAction_xxxx)]; 223 | } else { 224 | return [self textView_WUTextSuggestionDisplayController_methodSignatureForSelector:aSelector]; 225 | } 226 | } 227 | 228 | - (void)textView_WUTextSuggestionDisplayController_forwardInvocation:(NSInvocation *)anInvocation { 229 | if ([NSStringFromSelector(anInvocation.selector) hasPrefix:WUTextSuggestionDisplayControllerUIMenuControllerActionSelectorPrefix]) { 230 | [[UIMenuController sharedMenuController].menuItems enumerateObjectsUsingBlock:^(UIMenuItem *obj, NSUInteger idx, BOOL *stop) { 231 | if (WUTextSuggestionDisplayControllerUIMenuControllerActionSelectorMatchesMenuItemTitle(anInvocation.selector, obj.title)) { 232 | [[WUTextSuggestionDisplayController activeTextSuggestionDisplayController] textSuggestionDisplayItemTapped:obj.textSuggestionDisplayItem]; 233 | } 234 | }]; 235 | } else { 236 | [self textView_WUTextSuggestionDisplayController_forwardInvocation:anInvocation]; 237 | } 238 | } 239 | 240 | @end -------------------------------------------------------------------------------- /WUTextSuggestionDemo/WUTextSuggestionDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 9D47DD81173E44D400015A40 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9D47DD80173E44D400015A40 /* UIKit.framework */; }; 11 | 9D47DD83173E44D400015A40 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9D47DD82173E44D400015A40 /* Foundation.framework */; }; 12 | 9D47DD85173E44D400015A40 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9D47DD84173E44D400015A40 /* CoreGraphics.framework */; }; 13 | 9D47DD8B173E44D400015A40 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9D47DD89173E44D400015A40 /* InfoPlist.strings */; }; 14 | 9D47DD8D173E44D400015A40 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D47DD8C173E44D400015A40 /* main.m */; }; 15 | 9D47DD91173E44D400015A40 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D47DD90173E44D400015A40 /* AppDelegate.m */; }; 16 | 9D47DD93173E44D400015A40 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 9D47DD92173E44D400015A40 /* Default.png */; }; 17 | 9D47DD95173E44D400015A40 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 9D47DD94173E44D400015A40 /* Default@2x.png */; }; 18 | 9D47DD97173E44D400015A40 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 9D47DD96173E44D400015A40 /* Default-568h@2x.png */; }; 19 | 9D47DD9A173E44D400015A40 /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9D47DD98173E44D400015A40 /* MainStoryboard.storyboard */; }; 20 | 9D47DDA5173E44EA00015A40 /* DemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D47DDA4173E44EA00015A40 /* DemoViewController.m */; }; 21 | 9D47DDAB173E454600015A40 /* WUTextSuggestionController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D47DDA8173E454600015A40 /* WUTextSuggestionController.m */; }; 22 | 9D47DDAC173E454600015A40 /* WUTextSuggestionDisplayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D47DDAA173E454600015A40 /* WUTextSuggestionDisplayController.m */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 9D47DD7D173E44D400015A40 /* WUTextSuggestionDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WUTextSuggestionDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | 9D47DD80173E44D400015A40 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 28 | 9D47DD82173E44D400015A40 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 29 | 9D47DD84173E44D400015A40 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 30 | 9D47DD88173E44D400015A40 /* WUTextSuggestionDemo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "WUTextSuggestionDemo-Info.plist"; sourceTree = ""; }; 31 | 9D47DD8A173E44D400015A40 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 32 | 9D47DD8C173E44D400015A40 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 33 | 9D47DD8E173E44D400015A40 /* WUTextSuggestionDemo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WUTextSuggestionDemo-Prefix.pch"; sourceTree = ""; }; 34 | 9D47DD8F173E44D400015A40 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 35 | 9D47DD90173E44D400015A40 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 36 | 9D47DD92173E44D400015A40 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = ""; }; 37 | 9D47DD94173E44D400015A40 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = ""; }; 38 | 9D47DD96173E44D400015A40 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; 39 | 9D47DD99173E44D400015A40 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/MainStoryboard.storyboard; sourceTree = ""; }; 40 | 9D47DDA3173E44EA00015A40 /* DemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoViewController.h; sourceTree = ""; }; 41 | 9D47DDA4173E44EA00015A40 /* DemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoViewController.m; sourceTree = ""; }; 42 | 9D47DDA7173E454600015A40 /* WUTextSuggestionController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WUTextSuggestionController.h; sourceTree = ""; }; 43 | 9D47DDA8173E454600015A40 /* WUTextSuggestionController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WUTextSuggestionController.m; sourceTree = ""; }; 44 | 9D47DDA9173E454600015A40 /* WUTextSuggestionDisplayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WUTextSuggestionDisplayController.h; sourceTree = ""; }; 45 | 9D47DDAA173E454600015A40 /* WUTextSuggestionDisplayController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WUTextSuggestionDisplayController.m; sourceTree = ""; }; 46 | /* End PBXFileReference section */ 47 | 48 | /* Begin PBXFrameworksBuildPhase section */ 49 | 9D47DD7A173E44D400015A40 /* Frameworks */ = { 50 | isa = PBXFrameworksBuildPhase; 51 | buildActionMask = 2147483647; 52 | files = ( 53 | 9D47DD81173E44D400015A40 /* UIKit.framework in Frameworks */, 54 | 9D47DD83173E44D400015A40 /* Foundation.framework in Frameworks */, 55 | 9D47DD85173E44D400015A40 /* CoreGraphics.framework in Frameworks */, 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | /* End PBXFrameworksBuildPhase section */ 60 | 61 | /* Begin PBXGroup section */ 62 | 9D47DD74173E44D300015A40 = { 63 | isa = PBXGroup; 64 | children = ( 65 | 9D47DD86173E44D400015A40 /* WUTextSuggestionDemo */, 66 | 9D47DD7F173E44D400015A40 /* Frameworks */, 67 | 9D47DD7E173E44D400015A40 /* Products */, 68 | ); 69 | sourceTree = ""; 70 | }; 71 | 9D47DD7E173E44D400015A40 /* Products */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 9D47DD7D173E44D400015A40 /* WUTextSuggestionDemo.app */, 75 | ); 76 | name = Products; 77 | sourceTree = ""; 78 | }; 79 | 9D47DD7F173E44D400015A40 /* Frameworks */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 9D47DD80173E44D400015A40 /* UIKit.framework */, 83 | 9D47DD82173E44D400015A40 /* Foundation.framework */, 84 | 9D47DD84173E44D400015A40 /* CoreGraphics.framework */, 85 | ); 86 | name = Frameworks; 87 | sourceTree = ""; 88 | }; 89 | 9D47DD86173E44D400015A40 /* WUTextSuggestionDemo */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 9D47DDA6173E454600015A40 /* WUTextSuggestion */, 93 | 9D47DD98173E44D400015A40 /* MainStoryboard.storyboard */, 94 | 9D47DDA3173E44EA00015A40 /* DemoViewController.h */, 95 | 9D47DDA4173E44EA00015A40 /* DemoViewController.m */, 96 | 9D47DD87173E44D400015A40 /* Supporting Files */, 97 | ); 98 | path = WUTextSuggestionDemo; 99 | sourceTree = ""; 100 | }; 101 | 9D47DD87173E44D400015A40 /* Supporting Files */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 9D47DD8F173E44D400015A40 /* AppDelegate.h */, 105 | 9D47DD90173E44D400015A40 /* AppDelegate.m */, 106 | 9D47DD88173E44D400015A40 /* WUTextSuggestionDemo-Info.plist */, 107 | 9D47DD89173E44D400015A40 /* InfoPlist.strings */, 108 | 9D47DD8C173E44D400015A40 /* main.m */, 109 | 9D47DD8E173E44D400015A40 /* WUTextSuggestionDemo-Prefix.pch */, 110 | 9D47DD92173E44D400015A40 /* Default.png */, 111 | 9D47DD94173E44D400015A40 /* Default@2x.png */, 112 | 9D47DD96173E44D400015A40 /* Default-568h@2x.png */, 113 | ); 114 | name = "Supporting Files"; 115 | sourceTree = ""; 116 | }; 117 | 9D47DDA6173E454600015A40 /* WUTextSuggestion */ = { 118 | isa = PBXGroup; 119 | children = ( 120 | 9D47DDA7173E454600015A40 /* WUTextSuggestionController.h */, 121 | 9D47DDA8173E454600015A40 /* WUTextSuggestionController.m */, 122 | 9D47DDA9173E454600015A40 /* WUTextSuggestionDisplayController.h */, 123 | 9D47DDAA173E454600015A40 /* WUTextSuggestionDisplayController.m */, 124 | ); 125 | name = WUTextSuggestion; 126 | path = ../../WUTextSuggestion; 127 | sourceTree = ""; 128 | }; 129 | /* End PBXGroup section */ 130 | 131 | /* Begin PBXNativeTarget section */ 132 | 9D47DD7C173E44D400015A40 /* WUTextSuggestionDemo */ = { 133 | isa = PBXNativeTarget; 134 | buildConfigurationList = 9D47DDA0173E44D400015A40 /* Build configuration list for PBXNativeTarget "WUTextSuggestionDemo" */; 135 | buildPhases = ( 136 | 9D47DD79173E44D400015A40 /* Sources */, 137 | 9D47DD7A173E44D400015A40 /* Frameworks */, 138 | 9D47DD7B173E44D400015A40 /* Resources */, 139 | ); 140 | buildRules = ( 141 | ); 142 | dependencies = ( 143 | ); 144 | name = WUTextSuggestionDemo; 145 | productName = WUTextSuggestionDemo; 146 | productReference = 9D47DD7D173E44D400015A40 /* WUTextSuggestionDemo.app */; 147 | productType = "com.apple.product-type.application"; 148 | }; 149 | /* End PBXNativeTarget section */ 150 | 151 | /* Begin PBXProject section */ 152 | 9D47DD75173E44D300015A40 /* Project object */ = { 153 | isa = PBXProject; 154 | attributes = { 155 | LastUpgradeCheck = 0460; 156 | ORGANIZATIONNAME = YuAo; 157 | }; 158 | buildConfigurationList = 9D47DD78173E44D300015A40 /* Build configuration list for PBXProject "WUTextSuggestionDemo" */; 159 | compatibilityVersion = "Xcode 3.2"; 160 | developmentRegion = English; 161 | hasScannedForEncodings = 0; 162 | knownRegions = ( 163 | en, 164 | ); 165 | mainGroup = 9D47DD74173E44D300015A40; 166 | productRefGroup = 9D47DD7E173E44D400015A40 /* Products */; 167 | projectDirPath = ""; 168 | projectRoot = ""; 169 | targets = ( 170 | 9D47DD7C173E44D400015A40 /* WUTextSuggestionDemo */, 171 | ); 172 | }; 173 | /* End PBXProject section */ 174 | 175 | /* Begin PBXResourcesBuildPhase section */ 176 | 9D47DD7B173E44D400015A40 /* Resources */ = { 177 | isa = PBXResourcesBuildPhase; 178 | buildActionMask = 2147483647; 179 | files = ( 180 | 9D47DD8B173E44D400015A40 /* InfoPlist.strings in Resources */, 181 | 9D47DD93173E44D400015A40 /* Default.png in Resources */, 182 | 9D47DD95173E44D400015A40 /* Default@2x.png in Resources */, 183 | 9D47DD97173E44D400015A40 /* Default-568h@2x.png in Resources */, 184 | 9D47DD9A173E44D400015A40 /* MainStoryboard.storyboard in Resources */, 185 | ); 186 | runOnlyForDeploymentPostprocessing = 0; 187 | }; 188 | /* End PBXResourcesBuildPhase section */ 189 | 190 | /* Begin PBXSourcesBuildPhase section */ 191 | 9D47DD79173E44D400015A40 /* Sources */ = { 192 | isa = PBXSourcesBuildPhase; 193 | buildActionMask = 2147483647; 194 | files = ( 195 | 9D47DD8D173E44D400015A40 /* main.m in Sources */, 196 | 9D47DD91173E44D400015A40 /* AppDelegate.m in Sources */, 197 | 9D47DDA5173E44EA00015A40 /* DemoViewController.m in Sources */, 198 | 9D47DDAB173E454600015A40 /* WUTextSuggestionController.m in Sources */, 199 | 9D47DDAC173E454600015A40 /* WUTextSuggestionDisplayController.m in Sources */, 200 | ); 201 | runOnlyForDeploymentPostprocessing = 0; 202 | }; 203 | /* End PBXSourcesBuildPhase section */ 204 | 205 | /* Begin PBXVariantGroup section */ 206 | 9D47DD89173E44D400015A40 /* InfoPlist.strings */ = { 207 | isa = PBXVariantGroup; 208 | children = ( 209 | 9D47DD8A173E44D400015A40 /* en */, 210 | ); 211 | name = InfoPlist.strings; 212 | sourceTree = ""; 213 | }; 214 | 9D47DD98173E44D400015A40 /* MainStoryboard.storyboard */ = { 215 | isa = PBXVariantGroup; 216 | children = ( 217 | 9D47DD99173E44D400015A40 /* en */, 218 | ); 219 | name = MainStoryboard.storyboard; 220 | sourceTree = ""; 221 | }; 222 | /* End PBXVariantGroup section */ 223 | 224 | /* Begin XCBuildConfiguration section */ 225 | 9D47DD9E173E44D400015A40 /* Debug */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | ALWAYS_SEARCH_USER_PATHS = NO; 229 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 230 | CLANG_CXX_LIBRARY = "libc++"; 231 | CLANG_ENABLE_OBJC_ARC = YES; 232 | CLANG_WARN_CONSTANT_CONVERSION = YES; 233 | CLANG_WARN_EMPTY_BODY = YES; 234 | CLANG_WARN_ENUM_CONVERSION = YES; 235 | CLANG_WARN_INT_CONVERSION = YES; 236 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 237 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 238 | COPY_PHASE_STRIP = NO; 239 | GCC_C_LANGUAGE_STANDARD = gnu99; 240 | GCC_DYNAMIC_NO_PIC = NO; 241 | GCC_OPTIMIZATION_LEVEL = 0; 242 | GCC_PREPROCESSOR_DEFINITIONS = ( 243 | "DEBUG=1", 244 | "$(inherited)", 245 | ); 246 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 247 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 248 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 249 | GCC_WARN_UNUSED_VARIABLE = YES; 250 | IPHONEOS_DEPLOYMENT_TARGET = 6.1; 251 | ONLY_ACTIVE_ARCH = YES; 252 | SDKROOT = iphoneos; 253 | }; 254 | name = Debug; 255 | }; 256 | 9D47DD9F173E44D400015A40 /* Release */ = { 257 | isa = XCBuildConfiguration; 258 | buildSettings = { 259 | ALWAYS_SEARCH_USER_PATHS = NO; 260 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 261 | CLANG_CXX_LIBRARY = "libc++"; 262 | CLANG_ENABLE_OBJC_ARC = YES; 263 | CLANG_WARN_CONSTANT_CONVERSION = YES; 264 | CLANG_WARN_EMPTY_BODY = YES; 265 | CLANG_WARN_ENUM_CONVERSION = YES; 266 | CLANG_WARN_INT_CONVERSION = YES; 267 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 268 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 269 | COPY_PHASE_STRIP = YES; 270 | GCC_C_LANGUAGE_STANDARD = gnu99; 271 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 272 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 273 | GCC_WARN_UNUSED_VARIABLE = YES; 274 | IPHONEOS_DEPLOYMENT_TARGET = 6.1; 275 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; 276 | SDKROOT = iphoneos; 277 | VALIDATE_PRODUCT = YES; 278 | }; 279 | name = Release; 280 | }; 281 | 9D47DDA1173E44D400015A40 /* Debug */ = { 282 | isa = XCBuildConfiguration; 283 | buildSettings = { 284 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 285 | GCC_PREFIX_HEADER = "WUTextSuggestionDemo/WUTextSuggestionDemo-Prefix.pch"; 286 | INFOPLIST_FILE = "WUTextSuggestionDemo/WUTextSuggestionDemo-Info.plist"; 287 | PRODUCT_NAME = "$(TARGET_NAME)"; 288 | WRAPPER_EXTENSION = app; 289 | }; 290 | name = Debug; 291 | }; 292 | 9D47DDA2173E44D400015A40 /* Release */ = { 293 | isa = XCBuildConfiguration; 294 | buildSettings = { 295 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 296 | GCC_PREFIX_HEADER = "WUTextSuggestionDemo/WUTextSuggestionDemo-Prefix.pch"; 297 | INFOPLIST_FILE = "WUTextSuggestionDemo/WUTextSuggestionDemo-Info.plist"; 298 | PRODUCT_NAME = "$(TARGET_NAME)"; 299 | WRAPPER_EXTENSION = app; 300 | }; 301 | name = Release; 302 | }; 303 | /* End XCBuildConfiguration section */ 304 | 305 | /* Begin XCConfigurationList section */ 306 | 9D47DD78173E44D300015A40 /* Build configuration list for PBXProject "WUTextSuggestionDemo" */ = { 307 | isa = XCConfigurationList; 308 | buildConfigurations = ( 309 | 9D47DD9E173E44D400015A40 /* Debug */, 310 | 9D47DD9F173E44D400015A40 /* Release */, 311 | ); 312 | defaultConfigurationIsVisible = 0; 313 | defaultConfigurationName = Release; 314 | }; 315 | 9D47DDA0173E44D400015A40 /* Build configuration list for PBXNativeTarget "WUTextSuggestionDemo" */ = { 316 | isa = XCConfigurationList; 317 | buildConfigurations = ( 318 | 9D47DDA1173E44D400015A40 /* Debug */, 319 | 9D47DDA2173E44D400015A40 /* Release */, 320 | ); 321 | defaultConfigurationIsVisible = 0; 322 | }; 323 | /* End XCConfigurationList section */ 324 | }; 325 | rootObject = 9D47DD75173E44D300015A40 /* Project object */; 326 | } 327 | -------------------------------------------------------------------------------- /WUTextSuggestionDemo/WUTextSuggestionDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // WUTextSuggestionDemo 4 | // 5 | // Created by YuAo on 5/11/13. 6 | // Copyright (c) 2013 YuAo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /WUTextSuggestionDemo/WUTextSuggestionDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // WUTextSuggestionDemo 4 | // 5 | // Created by YuAo on 5/11/13. 6 | // Copyright (c) 2013 YuAo. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @implementation AppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 22 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application 42 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /WUTextSuggestionDemo/WUTextSuggestionDemo/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuAo/WUTextSuggestion/3884f37e2028735ca738d3bc24952066b9b1cdb1/WUTextSuggestionDemo/WUTextSuggestionDemo/Default-568h@2x.png -------------------------------------------------------------------------------- /WUTextSuggestionDemo/WUTextSuggestionDemo/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuAo/WUTextSuggestion/3884f37e2028735ca738d3bc24952066b9b1cdb1/WUTextSuggestionDemo/WUTextSuggestionDemo/Default.png -------------------------------------------------------------------------------- /WUTextSuggestionDemo/WUTextSuggestionDemo/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YuAo/WUTextSuggestion/3884f37e2028735ca738d3bc24952066b9b1cdb1/WUTextSuggestionDemo/WUTextSuggestionDemo/Default@2x.png -------------------------------------------------------------------------------- /WUTextSuggestionDemo/WUTextSuggestionDemo/DemoViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // DemoViewController.h 3 | // WUTextSuggestionDemo 4 | // 5 | // Created by YuAo on 5/11/13. 6 | // Copyright (c) 2013 YuAo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DemoViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /WUTextSuggestionDemo/WUTextSuggestionDemo/DemoViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // DemoViewController.m 3 | // WUTextSuggestionDemo 4 | // 5 | // Created by YuAo on 5/11/13. 6 | // Copyright (c) 2013 YuAo. All rights reserved. 7 | // 8 | 9 | #import "DemoViewController.h" 10 | #import "WUTextSuggestionController.h" 11 | #import "WUTextSuggestionDisplayController.h" 12 | 13 | @interface DemoViewController () 14 | @property (weak, nonatomic) IBOutlet UITextView *textView; 15 | @end 16 | 17 | @implementation DemoViewController 18 | 19 | - (void)viewDidLoad 20 | { 21 | [super viewDidLoad]; 22 | 23 | WUTextSuggestionDisplayController *suggestionDisplayController = [[WUTextSuggestionDisplayController alloc] init]; 24 | suggestionDisplayController.dataSource = self; 25 | 26 | WUTextSuggestionController *suggestionController = [[WUTextSuggestionController alloc] initWithTextView:self.textView suggestionDisplayController:suggestionDisplayController]; 27 | suggestionController.suggestionType = WUTextSuggestionTypeAt | WUTextSuggestionTypeHashTag; 28 | } 29 | 30 | #pragma mark - WUTextSuggestionDisplayControllerDataSource 31 | 32 | - (NSArray *)textSuggestionDisplayController:(WUTextSuggestionDisplayController *)textSuggestionDisplayController suggestionDisplayItemsForSuggestionType:(WUTextSuggestionType)suggestionType query:(NSString *)suggestionQuery 33 | { 34 | if (suggestionType == WUTextSuggestionTypeAt) { 35 | NSMutableArray *suggestionDisplayItems = [NSMutableArray array]; 36 | for (NSString *name in [self filteredNamesUsingQuery:suggestionQuery]) { 37 | WUTextSuggestionDisplayItem *item = [[WUTextSuggestionDisplayItem alloc] initWithTitle:name]; 38 | [suggestionDisplayItems addObject:item]; 39 | } 40 | return [suggestionDisplayItems copy]; 41 | } 42 | 43 | if (suggestionType == WUTextSuggestionTypeHashTag) { 44 | NSMutableArray *suggestionDisplayItems = [NSMutableArray array]; 45 | for (NSString *tag in [self filteredTagsUsingQuery:suggestionQuery]) { 46 | WUTextSuggestionDisplayItem *item = [[WUTextSuggestionDisplayItem alloc] initWithTitle:tag]; 47 | [suggestionDisplayItems addObject:item]; 48 | } 49 | return [suggestionDisplayItems copy]; 50 | } 51 | return nil; 52 | } 53 | 54 | /* You can use async callback 55 | 56 | - (void)textSuggestionDisplayController:(WUTextSuggestionDisplayController *)textSuggestionDisplayController suggestionDisplayItemsForSuggestionType:(WUTextSuggestionType)suggestionType query:(NSString *)suggestionQuery callback:(void (^)(NSArray *))gotSuggestionDisplayItemsBlock { 57 | dispatch_queue_t queryQueue = dispatch_queue_create("com.wutextsuggestion.query", DISPATCH_QUEUE_SERIAL); 58 | dispatch_async(queryQueue, ^{ 59 | if (suggestionType == WUTextSuggestionTypeAt) { 60 | NSMutableArray *suggestionDisplayItems = [NSMutableArray array]; 61 | for (NSString *name in [self filteredNamesUsingQuery:suggestionQuery]) { 62 | WUTextSuggestionDisplayItem *item = [[WUTextSuggestionDisplayItem alloc] initWithTitle:name]; 63 | [suggestionDisplayItems addObject:item]; 64 | } 65 | gotSuggestionDisplayItemsBlock(suggestionDisplayItems); 66 | } 67 | }); 68 | } 69 | 70 | */ 71 | 72 | #pragma mark - names 73 | 74 | - (NSArray *)filteredNamesUsingQuery:(NSString *)query { 75 | NSArray *filteredNames = [self.names filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { 76 | if ([[evaluatedObject lowercaseString] hasPrefix:[query lowercaseString]]) { 77 | return YES; 78 | } else { 79 | return NO; 80 | } 81 | }]]; 82 | return filteredNames; 83 | } 84 | 85 | - (NSArray *)names { 86 | return @[@"Abigail",@"Ada",@"Adela",@"Adelaide",@"Afra",@"Agatha",@"Agnes",@"Alberta",@"Alexia",@"Alice",@"Alma",@"Althea",@"Alva",@"Amanda",@"Amelia",@"Amy",@"Anastasia",@"Andrea",@"Angela",@"Ann",@"Anna",@"Annabelle",@"Antonia",@"April",@"Arabela",@"Arlene",@"Astrid",@"Atalanta",@"Athena",@"Audrey",@"Aurora",@"Barbara",@"Beatrice",@"Belinda",@"Bella",@"Belle",@"Bernice",@"Bertha",@"Beryl",@"Bess",@"Betsy",@"Betty",@"Beulah",@"Beverly",@"Blanche",@"Bblythe",@"Bonnie",@"Breenda",@"Bridget",@"Brook",@"Camille",@"Candance",@"Candice",@"Cara",@"Carol",@"Caroline",@"Catherine",@"Cathy",@"Cecilia",@"Celeste",@"Charlotte",@"Cherry",@"Cheryl",@"Chloe",@"Christine",@"Claire",@"Clara",@"Clementine",@"Constance",@"Cora",@"Coral",@"Cornelia",@"Crystal",@"Cynthia",@"Daisy",@"Dale",@"Dana",@"Daphne",@"Darlene",@"Dawn",@"Debby",@"Deborah",@"Deirdre",@"Delia",@"Denise",@"Diana",@"Dinah",@"Dolores",@"Dominic",@"Donna",@"Dora",@"Doreen",@"Doris",@"Dorothy",@"Eartha",@"Eden",@"Edith",@"Edwina",@"Eileen",@"Elaine",@"Eleanore",@"Elizabeth",@"Ella",@"Ellen",@"Elma",@"Elsa",@"Elsie",@"Elva",@"Elvira",@"Emily",@"Emma",@"Enid",@"Erica",@"Erin",@"Esther",@"Ethel",@"Eudora",@"Eunice",@"Evangeline",@"Eve",@"Evelyn",@"Faithe",@"Fanny",@"Fay",@"Flora",@"Florence",@"Frances",@"Freda",@"Frederica",@"Gabrielle",@"Gail",@"Gemma",@"Genevieve",@"Georgia",@"Geraldine",@"Gill",@"Giselle",@"Gladys",@"Gloria",@"Grace",@"Griselda",@"Gustave",@"Gwendolyn",@"Hannah",@"Harriet",@"Hazel",@"Heather",@"Hedda",@"Hedy",@"Helen",@"Heloise",@"Hermosa",@"Hilda",@"Hilary",@"Honey",@"Hulda",@"Ida",@"Ina",@"Ingrid",@"Irene",@"Iris",@"Irma",@"Isabel",@"Ivy",@"Jacqueline",@"Jamie",@"Jane",@"Janet",@"Janice",@"Jean",@"Jennifer",@"Jenny",@"Jessie",@"Jessica",@"Jill",@"Jo",@"Joa",@"Joanna",@"Joanne",@"Jocelyn",@"Jodie",@"Josephine",@"Joy",@"Joyce",@"Judith",@"Judy",@"Julia",@"Julie",@"Juliet",@"June",@"Kama",@"Karen",@"Katherine",@"Kay",@"Kelly",@"Kimberley",@"Kitty",@"Kristin",@"Laura",@"Laurel",@"Lauren",@"Lee",@"Leila",@"Lena",@"Leona",@"Lesley",@"Letitia",@"Lilith",@"Lillian",@"Linda",@"Lindsay",@"Lisa",@"Liz",@"Lorraine",@"Louise",@"Lucy",@"Lydia",@"Lynn",@"Mabel",@"Madeline",@"Madge",@"Maggie",@"Mamie",@"Mandy",@"Marcia",@"Margaret",@"Marguerite",@"Maria",@"Marian",@"Marina",@"Marjorie",@"Martha",@"Martina",@"Mary",@"Maud",@"Maureen",@"Mavis",@"Maxine",@"Mag",@"May",@"Megan",@"Melissa",@"Meroy",@"Meredith",@"Merry",@"Michelle",@"Michaelia",@"Mignon",@"Mildred",@"Mirabelle",@"Miranda",@"Miriam",@"Modesty",@"Moira",@"Molly",@"Mona",@"Monica",@"Muriel",@"Murray",@"Myra",@"Myrna",@"Nancy",@"Naomi",@"Natalie",@"Natividad",@"Nelly",@"Nicola",@"Nicole",@"Nina",@"Nora",@"Norma",@"Novia",@"Nydia",@"Octavia",@"Odelette",@"Odelia",@"Olga",@"Olive",@"Olivia",@"Ophelia",@"Pag",@"Page",@"Pamela",@"Pandora",@"Patricia",@"Paula",@"Pearl",@"Penelope",@"Penny",@"Philipppa",@"Phoebe",@"Phoenix",@"Phyllis",@"Polly",@"Poppy",@"Prima",@"Priscilla",@"Prudence",@"Queena",@"Quintina",@"Rachel",@"Rae",@"Rebecca",@"Regina",@"Renata",@"Renee",@"Rita",@"Riva",@"Roberta",@"Rosalind",@"Rose",@"Rosemary",@"Roxanne",@"Ruby",@"Ruth",@"Sabina",@"Sally",@"Sabrina",@"Salome",@"Samantha",@"Sandra",@"Sandy",@"Sara",@"Sarah",@"Sebastiane",@"Selena",@"Sharon",@"Sheila",@"Sherry",@"Shirley",@"Sibyl",@"Sigrid",@"Simona",@"Sophia",@"Spring",@"Stacey",@"Setlla",@"Stephanie",@"Susan",@"Susanna",@"Susie",@"Suzanne",@"Sylvia",@"Tabitha",@"Tammy",@"Teresa",@"Tess",@"Thera",@"Theresa",@"Tiffany",@"Tina",@"Tobey",@"Tracy",@"Trista",@"Truda",@"Ula",@"Una",@"Ursula",@"Valentina",@"Valerie",@"Vanessa",@"Venus",@"Vera",@"Verna",@"Veromca",@"Veronica",@"Victoria",@"Vicky",@"Viola",@"Violet",@"Virginia",@"Vita",@"Vivien",@"Wallis",@"Wanda",@"Wendy",@"Winifred",@"Winni",@"Xanthe",@"Xaviera",@"Xenia",@"Yedda",@"Yetta",@"Yvette",@"Yvonne",@"Zara",@"Zenobia",@"Zoe",@"Zona",@"Zora"]; 87 | } 88 | 89 | - (NSArray *)filteredTagsUsingQuery:(NSString *)query { 90 | NSArray *filteredTags = [self.tags filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { 91 | if ([[evaluatedObject lowercaseString] hasPrefix:[query lowercaseString]]) { 92 | return YES; 93 | } else { 94 | return NO; 95 | } 96 | }]]; 97 | return filteredTags; 98 | } 99 | 100 | - (NSArray *)tags { 101 | return @[@"HappyMothersDay",@"Apple",@"CleanSlate",@"HashTag",@"HelloWorld",@"ChangeOrDie",@"Caelondia"]; 102 | } 103 | 104 | @end 105 | -------------------------------------------------------------------------------- /WUTextSuggestionDemo/WUTextSuggestionDemo/WUTextSuggestionDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | YuAo.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | MainStoryboard 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /WUTextSuggestionDemo/WUTextSuggestionDemo/WUTextSuggestionDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'WUTextSuggestionDemo' target in the 'WUTextSuggestionDemo' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_5_0 8 | #warning "This project uses features only available in iOS SDK 5.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /WUTextSuggestionDemo/WUTextSuggestionDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /WUTextSuggestionDemo/WUTextSuggestionDemo/en.lproj/MainStoryboard.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /WUTextSuggestionDemo/WUTextSuggestionDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // WUTextSuggestionDemo 4 | // 5 | // Created by YuAo on 5/11/13. 6 | // Copyright (c) 2013 YuAo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | --------------------------------------------------------------------------------