实例iPhone编程入门教程-第三天
2011-09-22 14:19
337 查看
DAY THREE
- OPEN URL
大家一起来建立一个 iPhone app,给你的iPhone打开google地图有效地址连接。
首先运行以安装好的 xCode
选择: File->New Project.
从 "New Project" 窗口
选择 : iPhone OS ->Applications-> View-Based Application
命名 : 我这里命名为 "OpenURL"
(1) 在xCode打开 OpenURLViewController.h 文件,加入下面红色代码
#import <UIKit/UIKit.h>
@imterface OpenURLViewController : UIViewController{
}
-(IBaction)openMaps;
@end
(2) 在xCode打开 OpenURLViewController.m 文件,加入下面红色代码
#import <UIKit/UIKit.h#import "Day3ViewController.h"
@implementation Day3ViewController
// 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;
}
-(IBAction)openMaps{
NSString* addressText = @"1 Queen st, Auckland, NZ";
addressText = [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@",addressText];
//NSlog(urlText);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
}
@end
(3) UIView 界面设置
- 黑色背景,红色字体,让它看起来像一个闹钟。
双击文件: "OpenURLViewController.xib" ;
然后 "Interface Builder" 会自动打开,在这里我们可以编辑改变界面
选择: Tools -> Reveal In Document Window -> View
选择: Tools -> Attributes Inspector
在色条内选择 "黑色",可以看到背景变为黑色
(4) 加入 Button ,点击后打开连接
选择: Tools -> Library ;从Library显示菜单中拖拉一个 Button 到 Main View
在主显示上点击 Button;从Button Attributes 里面Title内填上 "Open Google Map"。
(5)从 Interface Builder 写入 UIButton 的 class file
再打开SDK工具 Interface Builder
在主视窗口或文件窗口;点击 Button
选择: Tools -> Connection Inspector
移动鼠标在"Touch Up Inside" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"File's Owner";
放开鼠标选择键出现 "openMaps"; 选上它。
选择: File -> Save then close Interface Builde
最后在 xCode 选择 Build->Build and Go
下载今天程序文件:
OpenURL.zip
- OPEN URL
大家一起来建立一个 iPhone app,给你的iPhone打开google地图有效地址连接。
首先运行以安装好的 xCode
选择: File->New Project.
从 "New Project" 窗口
选择 : iPhone OS ->Applications-> View-Based Application
命名 : 我这里命名为 "OpenURL"
(1) 在xCode打开 OpenURLViewController.h 文件,加入下面红色代码
#import <UIKit/UIKit.h>
@imterface OpenURLViewController : UIViewController{
}
-(IBaction)openMaps;
@end
(2) 在xCode打开 OpenURLViewController.m 文件,加入下面红色代码
#import <UIKit/UIKit.h#import "Day3ViewController.h"
@implementation Day3ViewController
// 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;
}
-(IBAction)openMaps{
NSString* addressText = @"1 Queen st, Auckland, NZ";
addressText = [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@",addressText];
//NSlog(urlText);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
}
@end
(3) UIView 界面设置
- 黑色背景,红色字体,让它看起来像一个闹钟。
双击文件: "OpenURLViewController.xib" ;
然后 "Interface Builder" 会自动打开,在这里我们可以编辑改变界面
选择: Tools -> Reveal In Document Window -> View
选择: Tools -> Attributes Inspector
在色条内选择 "黑色",可以看到背景变为黑色
(4) 加入 Button ,点击后打开连接
选择: Tools -> Library ;从Library显示菜单中拖拉一个 Button 到 Main View
在主显示上点击 Button;从Button Attributes 里面Title内填上 "Open Google Map"。
(5)从 Interface Builder 写入 UIButton 的 class file
再打开SDK工具 Interface Builder
在主视窗口或文件窗口;点击 Button
选择: Tools -> Connection Inspector
移动鼠标在"Touch Up Inside" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"File's Owner";
放开鼠标选择键出现 "openMaps"; 选上它。
选择: File -> Save then close Interface Builde
最后在 xCode 选择 Build->Build and Go
下载今天程序文件:
OpenURL.zip
相关文章推荐
- 实例iPhone编程入门教程-第六天
- 实例iPhone编程入门教程-第七天
- 实例iPhone编程入门教程-第八天
- 实例iPhone编程入门教程-第九天
- 实例iPhone编程入门教程-第十天
- 实例iPhone编程入门教程-第十一天
- 实例iPhone编程入门教程-第十二天
- 实例iPhone编程入门教程-第十三天
- 实例iPhone编程入门教程-第一天
- 实例iPhone编程入门教程-第二天
- 实例iPhone编程入门教程-第四天
- 实例iPhone编程入门教程-第五天
- ActiveMQ入门实例 - ActiveMQ教程
- sed与Awk教程入门与实例练习
- Spring MVC注解配置结合Hibernate的入门教程及其代码实例
- Expression Blend实例中文教程(4) - 布局控件快速入门Canvas
- Expression Blend实例中文教程(12) - 样式和模板快速入门Style,Template
- bpel 经典实例入门教程
- AJAX入门教程实例
- Yii2.0教程入门篇 —— 测试实例