UI第一个出画面的代码
来源:互联网 发布:易语言监听端口数据 编辑:程序博客网 时间:2024/04/30 09:29
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds] ] autorelease];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1000, 1000)];
self.window.backgroundColor = [UIColor grayColor];
[self.window addSubview:aView];
UITextField *firstNumber = [[UITextField alloc] initWithFrame:CGRectMake(20, 40, 50, 30)];
firstNumber.borderStyle = UITextBorderStyleRoundedRect;//输入框的样式
firstNumber.keyboardType = UIKeyboardTypeNumberPad;//弹出键盘样式
firstNumber.tag = 100;
[self.window addSubview:firstNumber];
[firstNumber release];
UILabel *plusLable = [[UILabel alloc] initWithFrame:CGRectMake(80, 40, 20, 30)];
plusLable.text = @"+"; //所显示的文本内容
plusLable.textAlignment = NSTextAlignmentCenter; //所显示的文本内容位置
[self.window addSubview:plusLable];
[plusLable release];
UITextField *secondNumber = [[UITextField alloc] initWithFrame:CGRectMake(110, 40, 50, 30)];
secondNumber.borderStyle = UITextBorderStyleRoundedRect;
secondNumber.keyboardType = UIKeyboardTypeNumberPad;
secondNumber.tag = 200;
[self.window addSubview:secondNumber];
[secondNumber release];
UILabel *resultLabel = [[UILabel alloc] initWithFrame:CGRectMake(230, 40, 30, 30)];
resultLabel.textAlignment = NSTextAlignmentLeft;
resultLabel.tag = 300;
[self.window addSubview:resultLabel];
[resultLabel release];
UIButton *caulatorButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
caulatorButton.frame = CGRectMake(170, 40, 50, 30);
[caulatorButton setTitle:@" = " forState:UIControlStateNormal];
[caulatorButton addTarget:self action:@selector(plus:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:caulatorButton];
return YES;
}
- (void)plus:(UIButton *)button
{
UITextField *firstTf = (UITextField *)[self.window viewWithTag:100];
UITextField *secondTf = (UITextField *)[self.window viewWithTag:200];
NSString *firstNumberStr = firstTf.text;
NSString *secondNumberStr = secondTf.text;
int result = firstNumberStr.intValue + secondNumberStr.intValue;
UILabel *resultLable = (UILabel *)[self.window viewWithTag:300];
resultLable.text = [NSString stringWithFormat:@"%d",result];
}
// Override point for customization after application launch.
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds] ] autorelease];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1000, 1000)];
self.window.backgroundColor = [UIColor grayColor];
[self.window addSubview:aView];
UITextField *firstNumber = [[UITextField alloc] initWithFrame:CGRectMake(20, 40, 50, 30)];
firstNumber.borderStyle = UITextBorderStyleRoundedRect;//输入框的样式
firstNumber.keyboardType = UIKeyboardTypeNumberPad;//弹出键盘样式
firstNumber.tag = 100;
[self.window addSubview:firstNumber];
[firstNumber release];
UILabel *plusLable = [[UILabel alloc] initWithFrame:CGRectMake(80, 40, 20, 30)];
plusLable.text = @"+"; //所显示的文本内容
plusLable.textAlignment = NSTextAlignmentCenter; //所显示的文本内容位置
[self.window addSubview:plusLable];
[plusLable release];
UITextField *secondNumber = [[UITextField alloc] initWithFrame:CGRectMake(110, 40, 50, 30)];
secondNumber.borderStyle = UITextBorderStyleRoundedRect;
secondNumber.keyboardType = UIKeyboardTypeNumberPad;
secondNumber.tag = 200;
[self.window addSubview:secondNumber];
[secondNumber release];
UILabel *resultLabel = [[UILabel alloc] initWithFrame:CGRectMake(230, 40, 30, 30)];
resultLabel.textAlignment = NSTextAlignmentLeft;
resultLabel.tag = 300;
[self.window addSubview:resultLabel];
[resultLabel release];
UIButton *caulatorButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
caulatorButton.frame = CGRectMake(170, 40, 50, 30);
[caulatorButton setTitle:@" = " forState:UIControlStateNormal];
[caulatorButton addTarget:self action:@selector(plus:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:caulatorButton];
return YES;
}
- (void)plus:(UIButton *)button
{
UITextField *firstTf = (UITextField *)[self.window viewWithTag:100];
UITextField *secondTf = (UITextField *)[self.window viewWithTag:200];
NSString *firstNumberStr = firstTf.text;
NSString *secondNumberStr = secondTf.text;
int result = firstNumberStr.intValue + secondNumberStr.intValue;
UILabel *resultLable = (UILabel *)[self.window viewWithTag:300];
resultLable.text = [NSString stringWithFormat:@"%d",result];
}
0 0
- UI第一个出画面的代码
- 第二人生的源码分析(1)第一个画面
- 第二人生的源码分析(1)第一个画面
- 看到蔡健雅,你脑子里的第一个画面是什么。
- 编译出你的第一个内核
- AppScan扫描出的第一个漏洞
- 开发出高性能的网站,第一部分 — 20个客户端代码优化技巧(转)
- 开发出高性能的网站,第一部分 — 20个客户端代码优化技巧(转)
- 开发出高性能的网站,第一部分 — 20个客户端代码优化技巧 - 【推荐】
- 我的第一个UI程序
- ZeroMQ的第一个代码
- Hibernate的第一个代码
- 第一个UI界面
- vlc for Android播放视频第一帧出画面慢。
- 什么时候出第一个版本?
- 蔡军生先生第二人生的源码分析(1)第一个画面
- UI_01.第一个ios UI
- UI01-第一个UI程序
- [sql server] 行转列问题总结1 - 行转列
- 【转】向中级程序员转变的10个建议
- 【经典】常用的正则表达式
- Xcode 6中添加预编译pch文件
- iOS改变状态栏字体颜色
- UI第一个出画面的代码
- Supporting Different devices - Supporting Different Languages
- error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such
- UIButton
- SharePoint 2013 Nintex Workflow 工作流帮助(十一)
- iOS开发笔记
- android下拉刷新
- oracle中exp,imp的使用详解
- Oracle多表插入