实例iPhone编程入门教程-第七天
2011-09-22 14:51
204 查看
DAY SEVEN – Settings Bundle
今天建立一个 iPhone app,运用 Settings Bundle 设置运行程序
纲要:
-在程序显示前运行代码;
-UILabel的运用;
-把 Settings Bundle 加入程序;
首先运行以安装好的 xCode
选择: File->New Project. 从 "New Project" 窗口
选择 : iPhone OS ->Applications-> View-Based Application
命名 : 这里命名为 "SettingsBundle"
(1)
在 xCode
打开
File -> New File.. ;
选择
Settings Bundle; 命名为 Settings.bundle;
(2)
在
Setting.bundle 双击 Root.plist
把
PrefernceSpecifiers 前的三角向下,按下
,加入:
Item1,
Item2,
Item3,
Item4,
Item5,
Item6,
在
xCode
打开 File -> Save;
(3)
在xCode
打开
SettingBundleViewController.h
文件,加入代码
#import <UIKit/UIKit.h>
@interface SettingsBundleViewController : UIViewController {
IBOutlet UILabel *lblText;
IBOutlet UILabel *lblReadOnly;
IBOutlet UILabel *lblSlider;
IBOutlet UILabel *lblColor;
IBOutlet UILabel *lblToogle;
}
@property (nonatomic, retain) UILabel *lblText;
@property (nonatomic, retain) UILabel *lblReadOnly;
@property (nonatomic, retain) UILabel *lblSlider;
@property (nonatomic, retain) UILabel *lblColor;
@property (nonatomic, retain) UILabel *lblToogle;
@end
(4)
在xCode打开
SettingsBundleViewController.m
文件,加入下面代码
#import "SettingsBundleViewController.h"
@implementation SettingsBundleViewController
// 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 viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSString *textValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"textEntry_key"];
NSString *readOnlyValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"readOnly_key"];
NSString *sliderValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"slider_key"];
NSString *colorValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"colors_key"];
NSString *toogleValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"toogle_key"];
lblText.text = [NSString stringWithFormat:@"Text Value: %@", textValue];
lblReadOnly.text = [NSString stringWithFormat:@"Read Only Value: %@", readOnlyValue];
lblSlider.text = [NSString stringWithFormat:@"Slider Value: %@", sliderValue];
lblColor.text = [NSString stringWithFormat:@"Selected color value: %@", colorValue];
lblToogle.text = [NSString stringWithFormat:@"Toggle Control Value: %@", toogleValue];
}
// 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 {
[lblToogle release];
[lblText release];
[lblReadOnly release];
[lblSlider release];
[lblColor release];
[super dealloc];
}
@end
(5) UIView
界面设置
双击文件:
"SettingsBundleViewController.xib" ;
然后
"Interface Builder"
会自动打开,在这里我们可以编辑改变界面
选择:
Tools -> Reveal In Document Window -> View
选择: Tools -> Attributes Inspector
在色条内选择
"白色",可以看到背景变为黑色
(3) 加入 五个
Label
选择: Tools -> Label
; 从Library显示菜单中拖拉一个 Label
到
Main View
在
Interface Builder
在主视窗口或文件窗口;点击
Label
选择: Tools -> Connection Inspector
移动鼠标在"Touch Up Inside"
后面圆圈上;
圆圈变为(+);
拖向直线连接到"File's Owner";
放开鼠标选择键出现
"lblText"; 选上它。
其余四个label步骤同上分别选上
“lblReadOnly”,”lblSlider”,”lblToogle”,”lblColor”
选择:
File -> Save then close Interface Builde
最后在
xCode 选择
Build -> Build and Go
下载今天教程文件:
SettingsBundle.zip
今天建立一个 iPhone app,运用 Settings Bundle 设置运行程序
纲要:
-在程序显示前运行代码;
-UILabel的运用;
-把 Settings Bundle 加入程序;
首先运行以安装好的 xCode
选择: File->New Project. 从 "New Project" 窗口
选择 : iPhone OS ->Applications-> View-Based Application
命名 : 这里命名为 "SettingsBundle"
(1)
在 xCode
打开
File -> New File.. ;
选择
Settings Bundle; 命名为 Settings.bundle;
(2)
在
Setting.bundle 双击 Root.plist
把
PrefernceSpecifiers 前的三角向下,按下
,加入:
Item1,
Item2,
Item3,
Item4,
Item5,
Item6,
在
xCode
打开 File -> Save;
(3)
在xCode
打开
SettingBundleViewController.h
文件,加入代码
#import <UIKit/UIKit.h>
@interface SettingsBundleViewController : UIViewController {
IBOutlet UILabel *lblText;
IBOutlet UILabel *lblReadOnly;
IBOutlet UILabel *lblSlider;
IBOutlet UILabel *lblColor;
IBOutlet UILabel *lblToogle;
}
@property (nonatomic, retain) UILabel *lblText;
@property (nonatomic, retain) UILabel *lblReadOnly;
@property (nonatomic, retain) UILabel *lblSlider;
@property (nonatomic, retain) UILabel *lblColor;
@property (nonatomic, retain) UILabel *lblToogle;
@end
(4)
在xCode打开
SettingsBundleViewController.m
文件,加入下面代码
#import "SettingsBundleViewController.h"
@implementation SettingsBundleViewController
// 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 viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSString *textValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"textEntry_key"];
NSString *readOnlyValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"readOnly_key"];
NSString *sliderValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"slider_key"];
NSString *colorValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"colors_key"];
NSString *toogleValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"toogle_key"];
lblText.text = [NSString stringWithFormat:@"Text Value: %@", textValue];
lblReadOnly.text = [NSString stringWithFormat:@"Read Only Value: %@", readOnlyValue];
lblSlider.text = [NSString stringWithFormat:@"Slider Value: %@", sliderValue];
lblColor.text = [NSString stringWithFormat:@"Selected color value: %@", colorValue];
lblToogle.text = [NSString stringWithFormat:@"Toggle Control Value: %@", toogleValue];
}
// 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 {
[lblToogle release];
[lblText release];
[lblReadOnly release];
[lblSlider release];
[lblColor release];
[super dealloc];
}
@end
(5) UIView
界面设置
双击文件:
"SettingsBundleViewController.xib" ;
然后
"Interface Builder"
会自动打开,在这里我们可以编辑改变界面
选择:
Tools -> Reveal In Document Window -> View
选择: Tools -> Attributes Inspector
在色条内选择
"白色",可以看到背景变为黑色
(3) 加入 五个
Label
选择: Tools -> Label
; 从Library显示菜单中拖拉一个 Label
到
Main View
在
Interface Builder
在主视窗口或文件窗口;点击
Label
选择: Tools -> Connection Inspector
移动鼠标在"Touch Up Inside"
后面圆圈上;
圆圈变为(+);
拖向直线连接到"File's Owner";
放开鼠标选择键出现
"lblText"; 选上它。
其余四个label步骤同上分别选上
“lblReadOnly”,”lblSlider”,”lblToogle”,”lblColor”
选择:
File -> Save then close Interface Builde
最后在
xCode 选择
Build -> Build and Go
下载今天教程文件:
SettingsBundle.zip
相关文章推荐
- 实例iPhone编程入门教程-第九天
- 实例iPhone编程入门教程-第十天
- 实例iPhone编程入门教程-第十一天
- 实例iPhone编程入门教程-第十二天
- 实例iPhone编程入门教程-第十三天
- 实例iPhone编程入门教程-第一天
- 实例iPhone编程入门教程-第二天
- 实例iPhone编程入门教程-第三天
- 实例iPhone编程入门教程-第四天
- 实例iPhone编程入门教程-第五天
- 实例iPhone编程入门教程-第六天
- 实例iPhone编程入门教程-第八天
- Expression Blend实例中文教程(8) - 动画设计快速入门StoryBoard
- windows phone:Expression Blend实例中文教程(3) - 布局控件快速入门Grid
- 9秒学院Cocos2d-x入门教程(详细的实例和讲解)
- Pylons 入门实例教程 – 表单和文件上传
- PHP框架Yii系列教程(一):入门实例
- Android基础入门教程——5.2.2 Fragment实例精讲——底部导航栏的实现(方法2)
- Expression Blend实例中文教程(7) - 动画基础快速入门Animation
- Android基础入门教程——5.2.3 Fragment实例精讲——底部导航栏的实现(方法3)