程序功能:点击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. Application(basic)----Easyui

    一,效果图. 二,源代码. <!DOCTYPE html><html><head> <meta charset="UTF-8"> & ...

  2. Java中的流程控制(三)

    关于Java中的流程控制 关于Java中的流程控制 4.do while语句 do while语句的功能和while语句差不多,只不过它是在执行完第一次循环后才检测条件表达式的值,这意味着包含在大括号 ...

  3. gulp+browserfy模块化工具环境搭建

    1.下载ruby,在ruby环境下安装sass; 2.安装nodejs; 3.进入当前项目所在目录,在cmd命令行中输入npm install; 4.安装browserify和gulp 安装brows ...

  4. python request模块学习

    安装: pip install requests 使用: import requests HTTP请求:GET.POST.PUT.DELETE.HEAD.OPTIONS 1) get res = re ...

  5. java如何引入接口中定义的常量

    接口 (A.java) : package config; public interface A { String PROJECT_ROOT_DIR = System.getProperty(&quo ...

  6. 14-C语言宏

    目录: 一.宏定义 二.#x,##x使用和预定义宏 三.宏的高级使用(条件编译) 回到顶部 一.宏定义 1 宏是常用的预处理功能之一,是在编译之前进行宏替换,即将宏名替换成所定义的宏体. 2 优点:可 ...

  7. android-数据持久化

    动态文件 String FILE_NAME = "tempfile.tmp"; try { //读 FileInputStream fis = openFileInput(FILE ...

  8. Windows-1252对Latin1编码有改变(并不完全兼容),而且Latin1缺失了好多西欧字符(法语,德语,西班牙语都有)

    主要是80到9F的编码被改掉了.从latin1的控制字符,变成了可以输出的可见字符. latin1编码: ISO-8859-1   x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA x ...

  9. [2013.9.8网络首发]导入Android4.2源码里的Gallery2和Camera模块至Eclipse全过程

    [2013.9.8网络首发]导入Android4.2源码里的Gallery2和Camera模块至Eclipse全过程   google的android自带的apps写的是相当牛逼的,将其导入到ecli ...

  10. openStack error infos 调试

    glance image-create --name "RuiCheck" --disk-format qcow2 --container-format bare --is-pub ...