使用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中. ...
随机推荐
- 使用JavaScript操作DOM节点元素的常用方法(创建/删除/替换/复制等)
getElementById(id)这是通过id来访问某一元素,最常用的之一,例:<html><body><div id="myid">test ...
- SQL高级查询——50句查询(含答案)
-一个题目涉及到的50个Sql语句 --(下面表的结构以给出,自己在数据库中建立表.并且添加相应的数据,数据要全面些. 其中Student表中,SId为学生的ID) ----------------- ...
- Java -Dfile.encoding=UTF-8 出现乱码问题原因分析
这两天写了一个 Java 程序来玩,结果又遭遇了以前遇到过很多次的乱码问题,具体描述一下: 在 Mac 系统里面,常用的 Java 程序启动方式有如下几种: 1.通过 eclipse 执行 class ...
- [C语言](*p)++与 ++(*p)与 *p++ 与 ++*p
首先亮明个人观点,不要认为这样写都算写的不好,还强调大神一般不写这种代码,可读性不高 其实是你的C语言基础太差,读不懂,大神还真的就是这么写的.可以看看C语言库函数中的一些写法 *P++ :*和++都 ...
- 自定义ViewPager控制是否滑动
package com.lvshandian.menshen.view;/** * Created by zhang on 2016/11/8. * 创建自定义滑动,禁止滑动的ViewPager */ ...
- Struts2的输入校验(1)——校验规则文件的编写
Struts2的输入校验(1) --校验规则文件的编写 Struts2提供了基于验证框架的输入校验,所有的输入校验只要编写配置文件,Struts2的验证框架将会负责进行服务器校验和客户端校验. 注: ...
- 真正意义上下一代 Windows Embedded:有关 Windows 10 "Athens" 的事
早在去年 BUILD 大会上,Joe Belfiore 就在一台巨大的 "脚踩钢琴" 上简短展示过 "Windows on Device"(又名 Windows ...
- 01.AFNetworking原理及常用操作
AFN的六大模块 NSURLConnection,主要对NSURLConnection进行了进一步的封装,包含以下核心的类: AFURLConnectionOperation AFHTTPReques ...
- JS中string对象的一些方法
原文地址(包含所有的string对象的方法): http://www.dreamdu.com/javascript/object_string/ string.slice(startPos,endP ...
- Know How To Use ID_NULL Function To Search An Object In Oracle Forms
ID_NULL built in function is used to determine that an object type variable is null or not null in O ...