1天学习1个类 UIBarButtomItem 类 示例
来源:互联网 发布:阿里云客服抢班语录 编辑:程序博客网 时间:2024/06/03 06:43
先看演示后面直接发代码部分.
没有全部测试完API,部分测试代码注释.大家可以自己测试.
示例全部采用代码实现..
新建工程->empty application
删除Applegate.h和Applegate.m 修改main.m文件.粘贴下面代码
//// main.m// ControlDemo//// Created by watsy0007 on 12-6-3.// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.//#import <UIKit/UIKit.h>@interface ViewController : UIViewController @property (nonatomic) NSInteger nDepth;@end@implementation ViewController@synthesize nDepth = _nDepth;- (id) init { if (self = [super init]) { _nDepth = 0; } return self;}- (void) BarButtonItemAction:(id) sender { if (_nDepth == 0) { ViewController *vc = [[ViewController alloc] init]; vc.nDepth = self.nDepth + 1; [self.navigationController pushViewController:vc animated:YES]; [vc release]; }}- (UIBarButtonItem *) createNewItemWith { UIBarButtonItem *item; // item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(BarButtonItemAction:)]; item = [[UIBarButtonItem alloc] initWithTitle:@"watsy0007" style:UIBarButtonItemStylePlain target:self action:@selector(BarButtonItemAction:)]; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)]; view.backgroundColor = [UIColor blueColor]; // item = [[UIBarButtonItem alloc] initWithCustomView:view];// item.customView = view; item.target = self; item.action = @selector(BarButtonItemAction:); item.style = UIBarButtonItemStylePlain; item.tintColor = [UIColor colorWithRed:155.0 / 255.0 green:155.0 / 255.0 blue:155.0 / 255.0 alpha:0.7]; [item setTitle:@"push"]; //设置标题显示的位置 [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setBackButtonTitlePositionAdjustment:UIOffsetMake(20, 5) forBarMetrics:UIBarMetricsDefault]; [view release]; return [item autorelease];}- (void) loadView { [super loadView]; UILabel *label = [[UILabel alloc] initWithFrame:self.view.bounds]; label.numberOfLines = 3; label.textAlignment = UITextAlignmentCenter; label.text = @"watsy0007 \n QQ:258841679\n群:125807534"; [self.view addSubview:label]; [label release]; self.title = @"UIBarButtomItem Class Reference Demo"; if (self.nDepth == 0) { self.navigationItem.rightBarButtonItem = [self createNewItemWith]; } }- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return YES;}- (void) viewDidLoad { [super viewDidLoad]; }@end@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@property (strong, nonatomic) UIViewController *viewController;@end@implementation AppDelegate@synthesize window = _window;@synthesize viewController = _viewController;- (void) dealloc { [_window release]; [_viewController release]; [super dealloc];}- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.viewController = [[ViewController alloc] init]; UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:self.viewController]; self.window.rootViewController = controller; [controller release]; [self.window makeKeyAndVisible]; return YES;}@endint main(int argc, char *argv[]){ @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }}
- 1天学习1个类 UIBarButtomItem 类 示例
- 1天学习1个类 UIButton 类 示例
- 1天学习1个类 UIDatePicker 类 示例
- 1天学习1个类 UIImagePickerController 示例
- springboot学习笔记-1 第一个springboot示例
- Mongodb MapReduce示例1个
- SQLLoader学习示例1
- Makefile学习之一个示例
- 1天学习1个类库 UILocalNotification 示例
- Python学习(1)----教材示例
- css示例学习---文字特效1
- webservice学习代码示例(1)
- Log4J学习【二】第一个日志示例
- Log4J学习【二】第一个日志示例
- JavaScript 中的 10 个机器学习示例
- 10个机器学习的JavaScript示例
- 1天学习1个类库 UIMapView annomation 示例
- 1天学习1个类库 MKMapView Overlay示例
- 黑马程序员_学习日记26_ASP.NET使用验证控件
- JQuery注册触发自定义事件
- 过了30岁,程序员该怎么办?
- FL2440_uCOS-II+ucGUI移植
- 黑马程序员_学习日记27_ASP.NET使用Rich控件
- 1天学习1个类 UIBarButtomItem 类 示例
- UESTC Training for Graph Theory——M、Network
- [Android]自定义移动网络接入点
- 嵌入式系统设计师考试笔记之接口技术(转)
- java jdk和cglib动态代理
- ios学习笔记(二)xcode 4.3.2下实现基本交互
- UESTC Training for Graph Theory——N、滑雪与时间胶囊(Large Input)
- 黑马程序员_学习日记29_winphone7开发_概述
- C#之电脑端口扫描器...