iOS UI基础-1.0加法计算器












@interface MJViewController ()
// 这里先把IBAction看做是void
- (IBAction)compute;
@end
@implementation MJViewController
- (void)compute
{
NSLog(@"点击了计算按钮");
}
@end



方法左边的圈圈由空心变为实心,说明已经跟某个按钮进行了连线
就这样,重新运行程序后,点击“计算”按钮,就会自动调用compute方法了,控制台已经有输出信息
@property (nonatomic, weak) IBOutlet UITextField *number1;
@property (nonatomic, weak) IBOutlet UITextField *number2;
@property (nonatomic, weak) IBOutlet UILabel *result;

- 利用MJViewController的number1属性就能访问第1个文本框;
- 利用MJViewController的number2属性就能访问第2个文本框;
- 利用MJViewController的result属性就能访问右边的文本标签。
- (void)compute
{
// 获取第一个数值
int num1 = [self.number1.text intValue];
// 获取第二个数值
int num2 = [self.number2.text intValue];
// 设置文本标签的值
self.result.text = [NSString stringWithFormat:@"%d", num1 + num2]; //参数表示强行关闭键盘,始终使用YES作为参数
[self.view endEditing:YES];
}
OK,大功告成!看效果
iOS UI基础-1.0加法计算器的更多相关文章
- iOS UI基础-17.0 UILable之NSMutableAttributedString
在iOS开发中,常常会有一段文字显示不同的颜色和字体,或者给某几个文字加删除线或下划线的需求.之前在网上找了一些资料,有的是重绘UILabel的textLayer,有的是用html5实现的,都比较麻烦 ...
- iOS UI基础-9.0 UITableView基础
在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView.UITableView继承自UIScrollView,因此支持垂直滚动,而且性能极佳. UITableView有两种样式: ...
- iOS UI基础-4.0应用程序管理
功能与界面 功能分析: 以九宫格的形式展示应用信息 点击下载按钮后,做出相应的操作 步骤分析: 加载应用信息 根据应用的个数创建对应的view 监听下载按钮点击 整个应用界面: 程序实现 思路 UI布 ...
- iOS UI基础-19.0 UICollectionView
直接上代码,说明请看注释吧 1.继承三个代理 UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateF ...
- iOS UI基础-16.0 UIButton
回归自然,UIButton是我们使用最频烦的一个控件.下面,对该控件的一些常用方法进行一些总结. UIButton *payStateBtn = [UIButton buttonWithType:UI ...
- iOS UI基础-15.0 UIWebView
WebView介绍 知识点: 代码创建一个UIWebView OC调用html的js js页面调用OC 相关代码实现 代码创建一个UIWebView // 1.webView UIWebView *w ...
- iOS UI基础-13.0 数据存储
应用沙盒 每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录),与其他文件系统隔离.应用必须待在自己的沙盒里,其他应用不能访问该沙盒 应用沙盒的文件系统目录,如下图所示(假设应用的名称叫Lay ...
- iOS UI基础-12.0 Storyboard
storyboard创建控制器 1.先加载storyboard文件(Test是storyboard的文件名) UIStoryboard *storyboard = [UIStoryboard stor ...
- iOS UI基础-10.0 QQ聊天布局之键盘及文本使用
要实现的效果: 这里只说用到的几个知识点 1.图片包含文字 在设置文字的Frame的时候,使用背景(按钮)的尺寸,文字使用了内边距 背景图片,使用拉伸 /** * 返回一张可以随意拉伸不变形的图片 ...
随机推荐
- 题目1458:汉诺塔III(不一样的汉诺塔递归算法)
题目链接:http://ac.jobdu.com/problem.php?pid=1458 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- svn版本管理
代码发布方案: 1,安装,优化 软件环境,(nginx,lvs) <-------运维工程师 2,程序代码(不断更新). <--------开发工程师,(开发,运维都可以发布) 3, ...
- XSS 跨站脚本攻击(Cross Site Scripting)
xss表示Cross Site Scripting(跨站脚本攻击),它与SQL注入攻击类似,SQL注入攻击中以SQL语句作为用户输入,从而达到查询/修改/删除数据的目的,而在xss攻击中,通过插入恶意 ...
- select默认下拉箭头改变、option样式清除
谷歌.火狐.ie下 select 的默认下拉箭头图标差别还是比较大,一般我们都会清除默认样式,重新设计箭头图标: /* --ie清除--*/ select::-ms-expand{ display: ...
- linux消息队列编程实例
转自:linux 消息队列实例 前言: 消息队列就是一个消息的链表.可以把消息看作一个记录,具有特定的格式以及特定的优先级.对消息队列有写权限的进程可以向其中按照一定的规则添加新消息:对消息队列有读权 ...
- ggplot2绘制概率密度图
以下绘图以Weibull分布(韦伯分布.威布尔分布)为例 关于Weibull分布(韦伯分布.威布尔分布),请参考本人博客http://www.cnblogs.com/wwxbi/p/6141501.h ...
- Linux wc
命令参数: -c 统计字节数. -l 统计行数. -m 统计字符数.这个标志不能与 -c 标志一起使用. -w 统计字数.一个字被定义为由空白.跳格或换行字符分隔的字符串. -L 打印最长行的长度. ...
- 170814、Java使用gzip压缩文件、还原文件
package com.rick.utils; import java.io.*; import java.util.zip.GZIPInputStream; import java.util.zip ...
- Java String, StringBuffer和StringBuilder实例
1- 分层继承2- 可变和不可变的概念3- String3.1- 字符串是一个非常特殊的类3.2- String 字面值 vs. String对象3.3- String的方法3.3.1- length ...
- PAT甲1038 Recover the smallest number
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...