• ios 给键盘上面加上“完成”


    #import <UIKit/UIKit.h>
    
    @interface FirstViewController : UIViewController<UITextFieldDelegate>
    {
        UITextField *textField1;
        UITextField *textField2;
        UISegmentedControl *_prevNext;
    }
    - (UIToolbar *)createActionBar;
    @end
    //
    //  FirstViewController.m
    //  MyTableViewDemo
    //
    //  Created by Chocolate on 13-9-12.
    //  Copyright (c) 2013年 Chocolate. All rights reserved.
    //
    
    #import "FirstViewController.h"
    
    @interface FirstViewController ()
    
    @end
    
    @implementation FirstViewController
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        textField1 = [[UITextField alloc]initWithFrame:CGRectMake(10, 20, 300, 40)];
        [textField1 setBorderStyle:UITextBorderStyleRoundedRect];
        [textField1 setReturnKeyType:UIReturnKeyNext];
        [textField1 setDelegate:self];
        textField2.inputAccessoryView = [self createActionBar];
        [textField1 setTag:1];
        [textField1 setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
        [self.view addSubview:textField1];
        
        textField2 = [[UITextField alloc]initWithFrame:CGRectMake(10, 80, 300, 40)];
        [textField2 setBorderStyle:UITextBorderStyleRoundedRect];
        [textField2 setReturnKeyType:UIReturnKeyDone];
         [textField2 setDelegate:self];
        textField2.inputAccessoryView = [self createActionBar];
        [textField2 setTag:2];
        [textField2 setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
        [self.view addSubview:textField2];
    }
    
    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        switch (textField.tag) {
            case 1:
                [textField2 becomeFirstResponder];
                break;
            case 2:
                [textField2 resignFirstResponder];
                break;
            default:
                break;
        }
        return YES;
    }
    
    -(UIToolbar *)createActionBar {
        UIToolbar *actionBar = [[UIToolbar alloc] init];
        actionBar.translucent = YES;
        [actionBar sizeToFit];
        actionBar.barStyle = UIBarStyleBlackTranslucent;
        
        UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", @"")
                                                                       style:UIBarButtonItemStyleDone target:self
                                                                      action:@selector(handleActionBarDone:)];
        
        _prevNext = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:NSLocalizedString(@"Previous", @""), NSLocalizedString(@"Next", @""), nil]];
        _prevNext.momentary = YES;
        _prevNext.segmentedControlStyle = UISegmentedControlStyleBar;
        _prevNext.tintColor = actionBar.tintColor;
        [_prevNext addTarget:self action:@selector(handleActionBarPreviousNext:) forControlEvents:UIControlEventValueChanged];
        UIBarButtonItem *prevNextWrapper = [[UIBarButtonItem alloc] initWithCustomView:_prevNext];
        UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        [actionBar setItems:[NSArray arrayWithObjects:prevNextWrapper, flexible, doneButton, nil]];
        
        return actionBar;
    }
    
    - (void)handleActionBarPreviousNext:(UISegmentedControl *)control
    {
        const BOOL isNext = control.selectedSegmentIndex == 1;
        if (isNext) {
            NSLog(@"next");
        } else {
            NSLog(@"previous");
        }
        [control setSelectedSegmentIndex:UISegmentedControlNoSegment];
    }
    
    - (BOOL)handleActionBarDone:(UIBarButtonItem *)doneButton {
            
        return NO;
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
  • 相关阅读:
    kubernetes案例 tomcat+mysql
    elasticsearch+logstash+kibana部署
    elasticsearch集群部署以及head插件安装
    Rhel7.4系统部署cobbler
    部署Hadoop2.0高性能集群
    使用haproxy实现负载均衡集群
    nginx实现动静分离的负载均衡集群
    heartrbeat实现web服务器高可用
    keepalived+lvs
    LVS集群之IP TUN模式以及网站压力测试
  • 原文地址:https://www.cnblogs.com/lihaibo-Leao/p/3316907.html
Copyright © 2020-2023  润新知