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

    xiaoxiao2022-06-29  60

    #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];

        

    }

    转载请注明原文地址: https://ju.6miu.com/read-1125471.html

    最新回复(0)