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

UIKit 手写控件转换大小写

2015-11-11 00:00 281 查看
//
// 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,strong) UITextField *input;
@property(nonatomic,strong) UILabel *output;
-(void)Upper;
-(void)Lower;
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: