您的位置:首页 > 产品设计 > UI/UE

UITextField 键盘上弹出"完成"字样

2016-09-14 15:31 295 查看
#import <UIKit/UIKit.h>

@interface QYTextField :
UITextField

@property (nonatomic,strong)
UIToolbar *toolbar;

@end

#import "QYTextField.h"

@implementation QYTextField

- (id)initWithFrame:(CGRect)frame{

    

    self = [superinitWithFrame:frame];

    if (self) {

        [self setup];

    }

    return
self;

}

- (void)setup{

    

    self.toolbar = [[UIToolbaralloc]
init];

    self.toolbar.frame =CGRectMake(0,0,
self.window.frame.size.width,44);

    // set style

    [self.toolbarsetBarStyle:UIBarStyleDefault];

    

    UIBarButtonItem *flexBarButton = [[UIBarButtonItemalloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:nilaction:nil];

    

    UIBarButtonItem *doneBarButton = [[UIBarButtonItemalloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDonetarget:selfaction:@selector(doneButtonIsClicked:)];

    

    NSArray *barButtonItems =
@[flexBarButton, doneBarButton];

    

    self.toolbar.items = barButtonItems;

    

    [selfsetInputAccessoryView:self.toolbar];

    

}

- (void) doneButtonIsClicked:(id)sender{

    

    [selfresignFirstResponder];

    

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: