该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实例编程入门教程》的更多相关文章

  1. 七、考反映小游戏《苹果iOS实例编程入门教程》

    该app为应用的功能为一个简单的考反应游戏 纲要:-UIButton, UILabel, UIImageView 的运用:-利用rendom增加游戏可玩性: 游戏说明: 在按下开始游戏后,分为三盏的指 ...

  2. 六、雪花《苹果iOS实例编程入门教程》

    该app为应用的功能为制作一场雪景 现版本 SDK 8.4 Xcode 纲要:- UIImageView 的运用- onTimer 代码运用- onAnimation 代码运用 运行Xcode 选择 ...

  3. 四、卫星定位《苹果iOS实例编程入门教程》

    该app为应用的功能为用iPhone 显示你现在的位置 现版本 SDK 8.4 Xcode 运行Xcode 选择 Create a new Xcode project ->Single View ...

  4. 三、图像移动《苹果iOS实例编程入门教程》

    该app为应用的功能为动态移动动画 现版本 SDK 8.4 Xcode 运行Xcode 选择 Create a new Xcode project ->Single View Applicati ...

  5. 二 、打开地图《苹果iOS实例编程入门教程》

    该app为应用的功能为给你的iPhone打开google地图有效地址连接 现版本 SDK 8.4 Xcode 运行Xcode 选择 Create a new Xcode project ->Si ...

  6. 一、午夜倒数《苹果iOS实例编程入门教程》

    该app为应用的功能为计算离午夜12:00点的剩余时间 现版本 SDK 8.4 Xcode 运行Xcode 选择 Create a new Xcode project ->Single View ...

  7. 【C语言C++编程学习笔记】基础语法,第一个简单的实例编程入门教程!

    C语言/C++编程学习:一个简单的实例 让我们来看一个简单的C语言程序.从下面的程序可以看出编写C语言程序的一些基本特征.   如果你能知道该程序将会在显示器上显示一些内容,那说明你还是知道一些的! ...

  8. VS2010/MFC编程入门教程之目录和总结

    鸡啄米的这套VS2010/MFC编程入门教程到此就全部完成了,虽然有些内容还未涉及到,但帮助大家进行VS2010/MFC的入门学习业已足够.以此教程的知识为基础,学习VS2010/MFC较为深入的内容 ...

  9. (转)VS2010-MFC编程入门教程之目录和总结

     目前该教程可以到鸡啄米编程课堂去学习,阅读体验更好,更适合在线学习. 原文目录及链接: 一.VS2010/MFC编程入门教程之目录 第一部分:VS2010/MFC开发环境 VS2010/MFC编程入 ...

随机推荐

  1. Win10 开发者模式开启

    使用注册表方式:建立一个注册表DWORD为1键值:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock\AllowAllTrust ...

  2. thinkphp分页样式

    html代码: <div class="pages">{$page}</div> css代码: .pages{ width:100.5%; text-ali ...

  3. 如何实现Outlook 2010 下载邮件后自动删除服务器上的邮件

    outlook2010---文件---信息---账户设置---选中要设置的帐号---双击点选要设置的邮箱---其他设置---高级---在服务器上保留邮件的副本---14天后删除服务器上的邮件副本,修改 ...

  4. Codeforces Round #227 (Div. 2) E. George and Cards set内二分+树状数组

    E. George and Cards   George is a cat, so he loves playing very much. Vitaly put n cards in a row in ...

  5. hdu 3001(状压dp, 3进制)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3001 由于本题中一个点最多能够访问2次,由此可以联想到3进制; visited[i][j]表示在状态i ...

  6. 把textarea右下角的灰点去掉

    这个是浏览器自带功能,那个区域属于滚动条的占位区 使textarea可以调整size,加 style="resize:none"可解决,添加多行文字时还是会出现滚动条的.

  7. C# 键值对类相关

    一 C# 键值对类有以下类: ①    IDictionary<string, Object> idc = new Dictionary<string, object>(); ...

  8. JavaScript设计模式——前奏

    Function.prototype.method = function(name,fn){ this.prototype[name] = fn; } var Anim = function(){ / ...

  9. AOP动态代理解析4-代理的创建

    做完了增强器的获取后就可以进行代理的创建了 AnnotationAwareAspectJAutoProxyCreator->postProcessAfterInitialization-> ...

  10. uva624 01背包要求输出路径

    You have a long drive by car ahead. You have a tape recorder, but unfortunately your best music is o ...