程序功能:点击Button实现按钮的文本变换

一,打开Xcode,新建single view based application,拖动一个Button控件到屏幕中间

项目目录树下包含AppDelegate.h AppDelegate.m MainStoryboard.storyboard ViewController.h ViewController.h等文件
其中MainStoryboard.storyboard用来设计UI界面,ViewController.*文件用来编码

ViewController.m代码如下

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} - (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
} - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} - (void)dealloc {
[super dealloc];
}
@end

ViewController.h代码如下

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@end

二,通过图形界面实现Button控件的属性(ID)及动作(Action)的配置

1,鼠标拖动Touch Down事件到ViewController.h文件,xcode会自动提示插入Action

2,设置Action名称为(OnBtnTouch)

3,同理,配置按钮的名称(ID),可以在程序中通过这个ID号控制控件

三,打开ViewController.m文件实现OnBtnTouch的具体逻辑,代码如下:

ViewController.m代码如下

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize ibtn; - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} - (void)viewDidUnload
{
[self setIbtn:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
} - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} - (void)dealloc {
[ibtn release];
[super dealloc];
}
- (IBAction)OnBtnTouch:(id)sender {
[ibtn setTitle:@"Go to Work!" forState:UIControlStateNormal];
}
@end

ViewController.h代码如下

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

- (IBAction)OnBtnTouch:(id)sender;

@property (retain, nonatomic) IBOutlet UIButton *ibtn;

@end

我们只手动添加了下面这行代码,其他都是xcode帮我们自动生成的

[ibtnsetTitle:@"Go to Work!"forState:UIControlStateNormal];

iphone开发小记的更多相关文章

  1. iPhone开发与cocos2d 经验谈

    转CSDN jilongliang : 首先,对于一个完全没有mac开发经验,甚至从没摸过苹果系统的开发人员来说,首先就是要熟悉apple的那一套开发框架(含开发环境IDE.开发框架uikit,还有开 ...

  2. iOS开发UI篇—iPad和iPhone开发的比较

    一.iPad简介 1.什么是iPad 一款苹果公司于2010年发布的平板电脑 定位介于苹果的智能手机iPhone和笔记本电脑产品之间 跟iPhone一样,搭载的是iOS操作系统 2.iPad的市场情况 ...

  3. iPad和iPhone开发区别

    原文:http://mobile.51cto.com/iphone-273895.htm iPad与iPhone 开发区别详解是本文要介绍的内容,先来看看他们的区别. 1.首先我们先从官方发布的SDK ...

  4. iPhone开发视频教程 Objective-C部分 (51课时)

    第一.二章  OC基础语法 iPhone开发教程 第一章 OC基础语法  iPhone开发概述-必看(1.1)http://www.apkbus.com/android-102215-1-1.html ...

  5. 【汇总】涉及iOS&iPhone开发相关文章汇总

    此文章汇总本博客中有涉及iPhone开发的相关文章,不定时更新中... 1.NSUserDefaults快速存储数据: http://www.cnblogs.com/ios-wmm/archive/2 ...

  6. iPhone开发常问的十个问题

    iPhone开发常问的十个问题 前言 今天去stackoverflow.com上看了一下iPhone标签下排名最高的10个问题,将它们整理出来,希望这些常见问题能帮到一些iPhone开发的初学者.本来 ...

  7. iOS开发教程之:iPhone开发环境搭建

    安装条件: 硬件:一台拥有支持虚拟技术的64位双核处理器和2GB以上内存的PC. 注意:运行MAC OS,需要电脑支持虚拟技术(VT),安装时,需要将VT启动,在BIOS中开启. 软件: Window ...

  8. iOS:iPad和iPhone开发的异同(UIPopoverController、UISplitViewController)

    iPad和iPhone开发的异同 1.iPhone和iPad: niPhone是手机,iPad.iPad Mini是平板电脑 iPhone和iPad开发的区别 屏幕的尺寸 \分辨率 UI元素的排布 \ ...

  9. 【转】iOS开发UI篇—iPad和iPhone开发的比较

    原文网址:http://www.cnblogs.com/wendingding/p/3918007.html iOS开发UI篇—iPad和iPhone开发的比较 一.iPad简介 1.什么是iPad ...

随机推荐

  1. [C#参考]细说进程、应用程序域与上下文之间的关系

    原文转载链接:http://www.cnblogs.com/leslies2/archive/2012/03/06/2379235.html Written by:风尘浪子 引言 本文主要是介绍进程( ...

  2. 加密解密技术—Web.config加密和解密

    阅读目录 一:我们为什么要对web.config配置文件中的配置节加密? 二:怎么样加密和解密? 三:实例 四:运行效果 一:我们为什么要对web.config配置文件中的配置节加密? 因为在我们的项 ...

  3. 阿里云ECS每天一件事D4:安装mysql5.5.40

    Linux平台上MySQL也没什么好说的了,首先准备一下软件环境: yum install gcc gcc-c++ gcc-g77 autoconf automake make cmake bison ...

  4. SendMessage发送WM_COMMAND消息控制另一个程序的某一个按钮

    procedure TfrmMain.btnSendClick(Sender: TObject); var hCalc, h1: Cardinal; begin WinExec('calc', SW_ ...

  5. 51nod 1239 欧拉函数之和(杜教筛)

    [题目链接] https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1239 [题目大意] 计算欧拉函数的前缀和 [题解] 我们 ...

  6. 贪吃蛇AI

    贪吃蛇AI 作者:CodeNoob 转载请标明作者和出处 序言 前几天在网上看到一张让人涨姿势的图片,这张图片我很早以前看过,当时就觉得肯定是程序实现的,只是当时还比较渣,不会算法.这次学了java也 ...

  7. How to choose between zombie.js and PhantomJS for automated web testing? [closed]

    How to choose between zombie.js and PhantomJS for automated web testing? [closed] How to choose betw ...

  8. Installing perl and writing your first perl program in Ubuntu

    Installing perl and writing your first perl program in Ubuntu     Installing perl and writing your f ...

  9. css学习笔记四

    广州天气变冷了,css学习笔记还是要总结. 总结: 1:几米页面静态页面主要是一列结构头部banner图,mainbody部分放文字内容和图书图片,底部是页面的版权信息 2:腾讯软件中心静态页面制作( ...

  10. div中央

    .histroyMsgSearch{ background:#Fff; text-align: center; }  CSS 怎样使DIV层水平居中 今天用CSS碰到个非常棘手的问题,DIV本身未定义 ...