我的iphone开发学习笔记(二)使用UITextView, UITextField 和UIButton控件
2011-11-30 22:53
741 查看
刚刚学习了一个实例,关于如何使用UITextField, UIButton的高级控件。
具体练习步骤如下:
1。 创建基于 view_base_application
命名为 FieldButtonFunApp
2. 打开FieldButtonFunViewController.h
依次添加需要的控件,并且@property 各个控件, 并且添加两个方法
3。 打开FieldFunButtonViewController.xib
添加需要的控件
5. 链接各个控件与file's owner
点击file's owner, 按住control,拖动到具体的控件,然后从列表中选择控件
依次完成
函数的链接方式相反,选中RoundRectButton,按住control到file‘s owner
看下图
6。完成FieldButtonFunViewController.m 中的函数
-(IBAction)createStory:(id)sender{
主要的代码就是提取指定字符,切换成相关的文字,看下代码,比较简单的;
}
7。运行效果,按下Command+R
点击createStory之后的效果为
8, 最后一个hideKeyboard方法的实现
该方法主要就是隐藏键盘,主要的代码如下,就是调用resignFirstResponder
好了,这个实例完成了。
具体练习步骤如下:
1。 创建基于 view_base_application
命名为 FieldButtonFunApp
2. 打开FieldButtonFunViewController.h
依次添加需要的控件,并且@property 各个控件, 并且添加两个方法
// // FielduttonFunViewController.h // FielduttonFun // // Created by 旭 陈 on 11-12-1. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import <UIKit/UIKit.h> @interface FielduttonFunViewController : UIViewController { IBOutlet UITextField *thePlace; IBOutlet UITextField *theVerb; IBOutlet UITextField *theNumber; IBOutlet UITextView *theStory; IBOutlet UITextView *theTemplate; IBOutlet UIButton *generateStory; } @property(retain,nonatomic) UITextField *thePlace; @property(retain,nonatomic) UITextField *theVerb; @property(retain,nonatomic) UITextField *theNumber; @property(retain,nonatomic) UITextView *theStory; @property(retain,nonatomic) UITextView *theTemplate; @property(retain,nonatomic) UIButton *generateStory; -(IBAction)createStory:(id)sender; -(IBAction)hideKeyboard:(id)sender; @end
3。 打开FieldFunButtonViewController.xib
添加需要的控件
5. 链接各个控件与file's owner
点击file's owner, 按住control,拖动到具体的控件,然后从列表中选择控件
依次完成
函数的链接方式相反,选中RoundRectButton,按住control到file‘s owner
看下图
6。完成FieldButtonFunViewController.m 中的函数
-(IBAction)createStory:(id)sender{
主要的代码就是提取指定字符,切换成相关的文字,看下代码,比较简单的;
}
// // FielduttonFunViewController.m // FielduttonFun // // Created by 旭 陈 on 11-12-1. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import "FielduttonFunViewController.h" @implementation FielduttonFunViewController @synthesize thePlace; @synthesize theVerb; @synthesize theNumber; @synthesize theStory; @synthesize theTemplate; @synthesize generateStory; /* // The designated initializer. Override to perform setup that is required before the view is loaded. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { // Custom initialization } return self; } */ /* // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } */ // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; } /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; [thePlace release]; [theVerb release]; [thePlace release]; [theTemplate release]; [theStory release]; } -(IBAction)createStory:(id)sender{ int i = 10; NSLog(@"%i", i); NSLog(@"creatStory%@",theTemplate.text); theTemplate.text = [theTemplate.text stringByReplacingOccurrencesOfString:@"<place>" withString:thePlace.text]; theTemplate.text = [theTemplate.text stringByReplacingOccurrencesOfString:@"<verb>" withString: theVerb.text]; theTemplate.text = [theTemplate.text stringByReplacingOccurrencesOfString:@"<number>" withString:theNumber.text]; theStory.text = theTemplate.text; NSLog(@"creatStory%@",theStory.text); } -(IBAction)hideKeyboard:(id)sender{ NSLog(@"hideKeyboard"); [thePlace resignFirstResponder]; [theVerb resignFirstResponder]; [theNumber resignFirstResponder]; [theTemplate resignFirstResponder]; } @end
7。运行效果,按下Command+R
点击createStory之后的效果为
8, 最后一个hideKeyboard方法的实现
该方法主要就是隐藏键盘,主要的代码如下,就是调用resignFirstResponder
-(IBAction)hideKeyboard:(id)sender{ NSLog(@"hideKeyboard"); [thePlace resignFirstResponder]; [theVerb resignFirstResponder]; [theNumber resignFirstResponder]; [theTemplate resignFirstResponder]; }
好了,这个实例完成了。
相关文章推荐
- 我的iphone开发学习笔记(九): 使用NSUserDefaults读写用户默认设置
- IOS 学习笔记(5) 控件 文本视图(UITextView)的使用方法
- IOS开发学习笔记018- 一般控件的使用
- iPhone开发学习笔记_剪切板的使用
- iPhone开发学习笔记[4/50]-表视图的使用
- 我的iphone开发学习笔记(四)使用UIWebView,UISegmentedControl
- ios学习笔记(一)Windows7上使用VMWare搭建iPhone开发环境
- 我的iphone开发学习笔记(六): 使用选项卡栏管理多视图界面
- IOS 学习笔记17 iPhone开发之使用NSUserDefaults存储数据
- 【iOS 开发】基本 UI 控件详解 (UIButton | UITextField | UITextView | UISwitch)
- 我的iphone开发学习笔记(三)使用UISlide, UIImageView及动画
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view
- ios 学习笔记(8) 控件 按钮(UIButton)的使用方法
- android 开发零起步学习笔记(十五):android: 静态XML和动态加载XML混合使用,以及重写Layout控件
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view
- ios学习笔记(一)Windows7上使用VMWare搭建iPhone开发环境
- IOS学习笔记(四)之UITextField和UITextView控件学习
- iPhone开发学习笔记001——Xib界面上的控件与代码的相互关联方法
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view
- WPF下的地图开发控件(GMap.NET)使用心得—— GMap学习笔记(二)