使用XIB实现一个简单view
技术处女贴 欢迎来探讨
转帖请注明出处 http://www.cnblogs.com/andy-zhou/p/4962135.html
微信: @Andy
1. AppDelegate
AppDelegate.h 文件
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@end
AppDelegate.m 文件
#import "AppDelegate.h"
#import "ViewController.h"
#import "AZImageViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// ViewController *viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
// self.window.rootViewController = viewController;
ViewController *viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
AZImageViewController *imageViewController = [[[AZImageViewController alloc] initWithNibName:@"AZImageViewController" bundle:nil] autorelease];
self.tabBarController = [[UITabBarController new] autorelease];
self.tabBarController.viewControllers = @[viewController, imageViewController];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
[_window release];
[super dealloc];
}
@end
2. ViewController
ViewController.h 文件
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (retain, nonatomic) IBOutlet UILabel *status;
- (IBAction)leftButtonPress:(id)sender;
- (IBAction)rightButtonPress:(id)sender;
- (IBAction)setStatusText:(id)sender;
@end
ViewController.m 文件
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize status;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"First", @"First");
self.tabBarItem.image = [UIImage imageNamed:@"first"];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[status release];
[super dealloc];
}
- (IBAction)leftButtonPress:(id)sender {
status.text = @"this is left btn";
}
- (IBAction)rightButtonPress:(id)sender {
status.text = @"this is right btn";
}
- (IBAction)setStatusText:(id)sender {
NSString *title = [sender titleForState:UIControlStateNormal];
// status.text = title;
NSString *newLableText = [NSString stringWithFormat:@"Hello, %@ btn", title];
status.text = newLableText;
}
@end
ViewController.xib 文件

3. AZImageViewController
AZImageViewController.h 文件
#import "ViewController.h"
@interface AZImageViewController : ViewController
@property (retain, nonatomic) IBOutlet UITextField *nameField;
@property (retain, nonatomic) IBOutlet UITextField *numberField;
@property (retain, nonatomic) IBOutlet UILabel *rateLabel;
- (IBAction)textFieldDoneEditing:(id)sender;
- (IBAction)backgroudTap:(id)sender;
- (IBAction)sliderMove:(id)sender;
@end
AZImageViewController.m 文件
#import "AZImageViewController.h"
@interface AZImageViewController ()
@end
@implementation AZImageViewController
@synthesize nameField;
@synthesize numberField;
@synthesize rateLabel;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Second", @"Second");
self.tabBarItem.image = [UIImage imageNamed:@"second"];
}
return self;
}
#pragma mark - Custom Method
- (IBAction)textFieldDoneEditing:(id)sender {
[sender resignFirstResponder];
}
- (IBAction)backgroudTap:(id)sender {
[nameField resignFirstResponder];
[numberField resignFirstResponder];
}
- (IBAction)sliderMove:(id)sender {
UISlider *slider = (UISlider *)sender;
NSInteger _rate = (NSInteger)roundf(slider.value);
rateLabel.text = [NSString stringWithFormat:@"%ld", _rate];
}
- (void)dealloc {
[nameField release];
[numberField release];
[rateLabel release];
[super dealloc];
}
@end
AZImageViewController.xib 文件

4. info_plist

使用XIB实现一个简单view的更多相关文章
- 使用xib封装一个自定义view的步骤
使用xib封装一个自定义view的步骤 1> 新建一个继承UIView的自定义view,假设类名叫做(MJAppView) 2> 新建一个MJAppView.xib文件来描述MJAppVi ...
- iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局
iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局 一.项目文件结构和plist文件 二.实现效果 三.代码示例 1.没有使用配套的类,而是直接使用xib文 ...
- iOS开发UI篇—使用picker View控件完成一个简单的选餐应用
iOS开发UI篇—使用picker View控件完成一个简单的选餐应用 一.实现效果 说明:点击随机按钮,能够自动选取,下方数据自动刷新. 二.实现思路 1.picker view的有默认高度为162 ...
- 相比xib 使用代码编排view 的一个明显的好处就是可以更好地重复使用已有代码,减少代码冗余。
相比xib 使用代码编排view 的一个明显的好处就是可以更好地重复使用已有代码,减少代码冗余.
- 在iOS中实现一个简单的画板App
在这个随笔中,我们要为iPhone实现一个简单的画板App. 首先需要指出的是,这个demo中使用QuarzCore进行绘画,而不是OpenGL.这两个都可以实现类似的功能,区别是OpenGL更快,但 ...
- 创建一个Table View
在本课程中,您将创建应用程序FoodTracker的主屏幕.您将创建第二个,表视图为主场景,列出了用户的菜谱.你会设计定制表格单元格显示每一个菜谱,它是这样的: 学习目标 在课程结束时,你将能够: 创 ...
- Objective-C ,ios,iphone开发基础:快速实现一个简单的图片查看器
新建一个single view 工程: 关闭ARC , 在.xib视图文件上拖放一个UIImageView 两个UIButton ,一个UISlider ,布局如图. 并为他们连线, UIImage ...
- IOS中一个简单的粒子效果实现
1.效果图展示 2.实现思路 1> 首先要实现上面的效果,第一步要处理的就是一个简单的画板,在View上面用鼠标滑动的时候画出线条,这个功能可使用UIBezierPath实现 2> 关于粒 ...
- CSharpGL(23)用ComputeShader实现一个简单的ParticleSimulator
CSharpGL(23)用ComputeShader实现一个简单的ParticleSimulator 我还没有用过Compute Shader,所以现在把红宝书里的例子拿来了,加入CSharpGL中. ...
随机推荐
- Intent官方教程(2)Intent的两种类型
Intent Types There are two types of intents: Explicit intents specify the component to start by name ...
- 掌握Tiles 框架 (一)---Tiles入门和Tiles 框架和体系结构
掌握Tiles 框架 (一)---Tiles入门和Tiles 框架和体系结构 入门 本教程所讲述的内容 本教程讲述如何使用 Tiles 框架来创建可重用的表示组件.(在最初创建它时,Tiles 框架被 ...
- #utf-8与gbk转换 #bytes 和str 的转换
#!/user/bin/env python # -*- coding:utf-8 -*- temp = "连接" temp_unicode = temp.decode('utf- ...
- git push 403
1. 在github上新建一个空项目. 2. git clone 到本地仓库. 3. git add [一些文件]. 4. git commit -m "first commit" ...
- VSFTP安全加固
这几天在公司需要做基线安全,一直都没有经验,所以在网上找了一些,做来参考学习. vsftp配置详解 这里是对vsftp配置文件的详细解释,主要参考了<RedHat8.0网络服务>一书中&l ...
- python_way,day8 面向对象【多态、成员--字段 方法 属性、成员修饰符、特殊成员、异常处理、设计模式之单例模式、模块:isinstance、issubclass】
python_way day8 一.面向对象三大特性: 多态 二.面向对象中的成员 字段.方法属性 三.成员修饰符 四.特殊成员 __init__.__doc__.__call__.__setitem ...
- CSS笔记(四)文本
CSS 文本属性可定义文本的外观.通过文本属性,可以改变文本的颜色.字符间距,对齐文本,装饰文本和对文本进行缩进,等等. 参考:http://www.w3school.com.cn/css/css_t ...
- css样式 浏览器的读取顺序
css样式 浏览器的读取顺序 例: tbody tr td{} 浏览器是先查找td,然后去找td tr,然后去找td tr tbody div p{}和div>p{}的区别 .div p{} 是 ...
- PL/SQL 听课笔记
PL/SQL: 知识回顾: SQL: 结构化查询语言: T-SQL: microsoft sql语言: PL/SQL: Oracle sql语言: 变量命名规则: 1.首字母必须是字母,可以包含字 ...
- HDU 1698
成段更新 这是一种把 num[]上空结点当做lazy标志使用的方法 都一样... #include <stdio.h> #include <string.h> #include ...