About iOS different types of keyboard switching

Source: Internet
Author: User

Gossip less, immediately into the subject ...

The switch between the keyboard and the system's default keyboard is used in the development with the Pickerview customization. Hope to help the friends to use ...

#import "ViewController.h"

@interface Viewcontroller () <uitextviewdelegate, Uitextfielddelegate, uipickerviewdelegate>

@property (Weak, nonatomic) Iboutlet Uitextfield *textfield;

@property (Weak, nonatomic) Iboutlet Uitextview *textview;

/** Custom Keyboard */

@property (nonatomic, strong) Uipickerview *pickerview;

/** cause array */

@property (nonatomic, strong) Nsarray *reasonarray;

@property (nonatomic, assign) BOOL IsFirst;

@end

@implementation Viewcontroller

-(Ibaction) Click: (ID) Sender {

[Self.textfield Resignfirstresponder];

}

-(void) Viewdidload {

[Super Viewdidload];

Self.textView.delegate = self;

Self.textField.delegate = self;

Self.textField.inputView = Self.pickerview;

}

-(void) Viewdidappear: (BOOL) Animated {

[Super viewdidappear:animated];

[Self.textfield Becomefirstresponder];

}

-(void) Viewdiddisappear: (BOOL) Animated {

[Super viewdiddisappear:animated];

[Self.textfield Resignfirstresponder];

}

/*****************************************/

#pragma mark-uitextviewdelegate

-(BOOL) textviewshouldbeginediting: (Uitextview *) TextView {

Toggle Keyboard

[Self.textfield Resignfirstresponder];

self.textField.enabled = NO;

Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (0.5 * nsec_per_sec)), Dispatch_get_main_queue (), ^{

[TextView Becomefirstresponder];

});

return YES;

}

-(void) textviewdidbeginediting: (Uitextview *) TextView {

self.textField.enabled = YES;

}

#pragma mark-uitextfielddelegate

-(BOOL) textfieldshouldbeginediting: (Uitextfield *) TextField {

Toggle Keyboard

[Self.textview Resignfirstresponder];

self.textView.editable = NO;

Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (0.5 * nsec_per_sec)), Dispatch_get_main_queue (), ^{

[TextField Becomefirstresponder];

});

if (_isfirst) {

[Self PickerView:self.pickerView didselectrow:0 incomponent:1];

_isfirst = NO;

}

return YES;

}

-(void) textfielddidbeginediting: (Uitextfield *) TextField {

self.textView.editable = YES;

}

Do not allow user input

-(BOOL) Texttitlefield: (Uitextfield *) Texttitlefield Shouldchangecharactersinrange: (nsrange) Range Replacementstring: (NSString *) string {

return NO;

}

/******************* Switch Keyboard **********************/

#pragma mark-uipickerviewreasonarraysource

-(Nsinteger) Numberofcomponentsinpickerview: (Uipickerview *) Pickerview {

return 1;

}

Number of rows

-(Nsinteger) Pickerview: (Uipickerview *) Pickerview numberofrowsincomponent: (Nsinteger) Component {

return self.reasonArray.count;

}

#pragma mark-uipickerveiwdelegate

-(NSString *) Pickerview: (Uipickerview *) Pickerview Titleforrow: (nsinteger) Row forcomponent: (Nsinteger) Component {

return Self.reasonarray[row];

}

Select a row

-(void) Pickerview: (Uipickerview *) Pickerview Didselectrow: (nsinteger) Row incomponent: (Nsinteger) Component {

Self.textField.text = Self.reasonarray[row];

}

#pragma mark-Lazy loading

-(Uipickerview *) Pickerview {

if (!_pickerview) {

_pickerview = [[Uipickerview alloc] init];

_pickerview.backgroundcolor = [Uicolor Lightgraycolor];

_pickerview.backgroundcolor = [Uicolor Whitecolor];

_pickerview.delegate = self;

}

return _pickerview;

}

-(Nsarray *) Reasonarray {

if (!_reasonarray) {

_reasonarray = @[@ "121313311", @ "121313311", @ "121313311", @ "121313311", @ "121313311", @ "121313311", @ "121313311", @ " 121313311 "@" 121313311 "@" 121313311 "@" 121313311 "@" 121313311 "];

}

return _reasonarray;

}

About iOS different types of keyboard switching

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.