UIKit 手写控件转换大小写

//

//  ViewController.m

//  手写转换大小写

//

//  Created by 非凡程序员 on 15/11/11.

//  Copyright (c) 2015 Querida. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 30, 200, 30)];

    label.text=@"要转化的字母";

    label.font=[UIFont fontWithName:@"Arial" size:15];

    [self.view addSubview:label];

    

    UILabel *labelI = [[UILabel alloc]initWithFrame:CGRectMake(20, 90, 200, 30)];

    labelI.text=@"转化后的字母";

    labelI.font=[UIFont fontWithName:@"Arial" size:15];

    [self.view addSubview:labelI];

    _output = [[UILabel alloc]initWithFrame:CGRectMake(120, 90, 200, 30)];

//    _output.backgroundColor=[UIColor blueColor];

    [self.view addSubview:_output];

    

   _input = [[UITextField alloc]initWithFrame:CGRectMake(120, 30, 200, 30)];

    _input.borderStyle=UITextBorderStyleLine;

    _input.textAlignment=NSTextAlignmentCenter;

    _input.placeholder=@"请输入内容";

    [self.view addSubview:_input];

    

    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(120, 130, 70, 30)];

    [button setTitle:@"转大写" forState:UIControlStateNormal];

    [button addTarget:self action:@selector(Upper) forControlEvents:UIControlEventTouchUpInside];

    button.backgroundColor =[UIColor blueColor];

    [button.layer setBorderWidth:1.0];

    [self.view addSubview:button];

    

    UIButton *buttonI = [[UIButton alloc]initWithFrame:CGRectMake(220, 130, 70, 30)];

    [buttonI setTitle:@"转小写" forState:UIControlStateNormal];

    [buttonI addTarget:self action:@selector(Lower) forControlEvents:UIControlEventTouchUpInside];

    buttonI.backgroundColor =[UIColor blueColor];

    [buttonI.layer setBorderWidth:1.0];

    [self.view addSubview:buttonI];

    

}

-(void)Upper{

    

    NSString *upper = _input.text;

    _output.text=[upper uppercaseString];

}


-(void)Lower{

    NSString *lower = _output.text;

    _output.text=[lower lowercaseString];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end



//

//  ViewController.h

//  手写转换大小写

//

//  Created by 非凡程序员 on 15/11/11.

//  Copyright (c) 2015 Querida. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface ViewController : UIViewController

@property(nonatomic,strongUITextField *input;

@property(nonatomic,strongUILabel *output;

-(void)Upper;

-(void)Lower;

@end



你可能感兴趣的:(UIKit 手写控件转换大小写)