五、点数器《苹果iOS实例编程入门教程》
该app为应用的功能为一个简单的数数程序
现版本 SDK 8.4 Xcode
运行Xcode 选择 Create a new Xcode project ->Single View Application 命名 CountMeIn
(1) 在xCode打开 CountMeInViewController.h 文件,加入下面代码
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UILabel *counter;
}
-(IBAction)reset:(id)sender;
-(IBAction)addUint:(id)sender;
-(IBAction)subtractUint:(id)sender;
@end
(2) 在xCode打开 CountMeInViewController.m 文件,加入下面代码
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
int count = 0;
//清零
-(IBAction)reset:(id)sender
{
count = 0;
counter.text = @"0";
}
//增加 最大为999
-(IBAction)addUint:(id)sender
{
if(count >= 999)return;
NSString *numValue = [[NSString alloc]initWithFormat:@"%d",++count];
counter.text = numValue;
}
//减少 最小为0
-(IBAction)subtractUint:(id)sender
{
if(count <0)return;
NSString *numValue = [[NSString alloc]initWithFormat:@"%d",--count];
counter.text = numValue;
}
- (void)viewDidLoad {
counter.text = @"0";
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
(3) 导入下面图片文件
将下面的图片导入到项目文件夹Supporting Files中(此为原博客中图片)
backgroundPattern IconGreenAdd IconRedSubtract

(4) UIView 界面设置
切换到main.storyboard
加入 Label ,显示程序计算结果
选择: Object Library 中拖拉一个 Label 到 Main View
鼠标右击Label控件,鼠标移动到"New Referencing Outlet" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"view controller";
放开鼠标选择键出现 "counter"; 选上它。
加入 Add Button , 进行累加计算
选择: Object Library 中拖拉一个 Button 到 Main View
鼠标右击Button控件,鼠标移动到"Touch Up Inside" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"view controller";
放开鼠标选择键出现 "addUnit"; 选上它。
属性设置切换到Attributes上在 Type 下选择 custom; 在 Background 下选择 iconGreenAdd
加入 Subtract Button , 进行累减计算
选择: Object Library 中拖拉一个 Button 到 Main View
鼠标右击Button控件,鼠标移动到"Touch Up Inside" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"view controller";
放开鼠标选择键出现 "SubtractUnit"; 选上它。
属性设置切换到Attributes上在 Type 下选择 custom; 在 Background 下选择 iconRedSubtract
加入 Reset Button , 进行清零
选择: Object Library 中拖拉一个 Button 到 Main View
鼠标右击Button控件,鼠标移动到"Touch Up Inside" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"view controller";
放开鼠标选择键出现 "Reset"; 选上它。
属性设置切换到Attributes上在 Title 下填上 Reset
加入 UIimageView , 背景图案
选择: Object Library 中拖拉一个 imageView 到 Main View
点击 imageView 属性设置切换到Attributes上在 image下选择backgroundPattern.png
点击菜单栏的Editor->Arrange->Send to Back(如果以设置为背景或者没有选中imageView控件,Send to Back可能为灰色)

Size to Fit Content 这个按钮能够根据包含的图片或文本而调整大小了
选择: File -> Save
最后在 xCode 选择 Build and then Running
(5)模拟器效果图

本文源于网上博客教程,经过本人修改和测试。原blog地址 http://blog.sina.com.cn/s/blog_5fae23350100dx96.html
五、点数器《苹果iOS实例编程入门教程》的更多相关文章
- 七、考反映小游戏《苹果iOS实例编程入门教程》
该app为应用的功能为一个简单的考反应游戏 纲要:-UIButton, UILabel, UIImageView 的运用:-利用rendom增加游戏可玩性: 游戏说明: 在按下开始游戏后,分为三盏的指 ...
- 六、雪花《苹果iOS实例编程入门教程》
该app为应用的功能为制作一场雪景 现版本 SDK 8.4 Xcode 纲要:- UIImageView 的运用- onTimer 代码运用- onAnimation 代码运用 运行Xcode 选择 ...
- 四、卫星定位《苹果iOS实例编程入门教程》
该app为应用的功能为用iPhone 显示你现在的位置 现版本 SDK 8.4 Xcode 运行Xcode 选择 Create a new Xcode project ->Single View ...
- 三、图像移动《苹果iOS实例编程入门教程》
该app为应用的功能为动态移动动画 现版本 SDK 8.4 Xcode 运行Xcode 选择 Create a new Xcode project ->Single View Applicati ...
- 二 、打开地图《苹果iOS实例编程入门教程》
该app为应用的功能为给你的iPhone打开google地图有效地址连接 现版本 SDK 8.4 Xcode 运行Xcode 选择 Create a new Xcode project ->Si ...
- 一、午夜倒数《苹果iOS实例编程入门教程》
该app为应用的功能为计算离午夜12:00点的剩余时间 现版本 SDK 8.4 Xcode 运行Xcode 选择 Create a new Xcode project ->Single View ...
- 【C语言C++编程学习笔记】基础语法,第一个简单的实例编程入门教程!
C语言/C++编程学习:一个简单的实例 让我们来看一个简单的C语言程序.从下面的程序可以看出编写C语言程序的一些基本特征. 如果你能知道该程序将会在显示器上显示一些内容,那说明你还是知道一些的! ...
- VS2010/MFC编程入门教程之目录和总结
鸡啄米的这套VS2010/MFC编程入门教程到此就全部完成了,虽然有些内容还未涉及到,但帮助大家进行VS2010/MFC的入门学习业已足够.以此教程的知识为基础,学习VS2010/MFC较为深入的内容 ...
- (转)VS2010-MFC编程入门教程之目录和总结
目前该教程可以到鸡啄米编程课堂去学习,阅读体验更好,更适合在线学习. 原文目录及链接: 一.VS2010/MFC编程入门教程之目录 第一部分:VS2010/MFC开发环境 VS2010/MFC编程入 ...
随机推荐
- RAC NTP/CTSS
本文總結主要參考: http://blog.itpub.net/23135684/viewspace-759693/ http://www.happyworld.net.cn/post/6.html ...
- <转>WCF中出现死锁或者超时
WCF回调中的死锁 一.服务器端死锁 对于如下服务: [ServiceContract(CallbackContract = typeof(INotify))] public class Downlo ...
- android 入门-android Studio git 克隆
最后是完成 以上是如何从android studio Git 克隆Github的项目
- [Oracle] 生产上表的列类型更新
由于粗心,数据库脚本生成的时候错将一个类型NUMBER(5)的字段类型改为 VARCHAR2(5) 直接进行表修改会报错,因为数据已经存在,不能进行更新: ); 大体思路如下: 将要更改类 ...
- 【c++】必须在类初始化列表中初始化的几种情况
转自:http://www.cnblogs.com/kaituorensheng/p/3477630.html 1. 类成员为const类型 2. 类成员为引用类型 #include <iost ...
- JavaScript中call,apply和prototype
[TOC] call()方法 语法:call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象. 如果没有提供 thi ...
- 【MongoDB】1.安装--以及简单使用
第一次接触MongoDB 参考&粘贴:http://jingyan.baidu.com/article/ed15cb1b52b8661be2698162.html 一.安装 1.首先去官 ...
- vim 分屏功能
分屏启动Vim 使用大写的O参数来垂直分屏. vim -On file1 file2 ... 使用小写的o参数来水平分屏. vim -on file1 file2 ... 注释: n是数字,表示分成几 ...
- 使用J2SE API读取Properties文件的六种方法
1.使用java.util.Properties类的load()方法示例: InputStream in = lnew BufferedInputStream(new FileInputStream( ...
- @import与link
本质上,这两种方式都是为了加载CSS文件,但还是存在着细微的差别. 1. 老祖宗的差别.link属于XHTML标签,而@import完全是CSS提供的一种方式. link标签除了可以加载CSS外,还可 ...