UITabBar
来源:互联网 发布:如何使淘宝店流量增加 编辑:程序博客网 时间:2024/05/01 03:05
#import "AppDelegate.h"#import "FirstViewController.h"#import "SecondViewController.h"#import "ThirdViewController.h"#import "ForthViewController.h"#import "FivthViewController.h"#import "SixthViewController.h"@interface AppDelegate ()<UITabBarControllerDelegate>@end@implementation AppDelegate- (void)dealloc{ [_window release]; [super dealloc];}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; [_window release]; // 创建第一个视图控制器对象 FirstViewController *firstVC = [[FirstViewController alloc] init];// 创建第一个naVC UINavigationController *firstNAVC = [[UINavigationController alloc] initWithRootViewController:firstVC];// 创建tabbar上的按钮及其内容 firstVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemHistory tag:1000] autorelease]; SecondViewController *secVC = [[SecondViewController alloc] init]; UINavigationController *secNAVC = [[UINavigationController alloc] initWithRootViewController:secVC]; UIImage *image = [UIImage imageNamed:@"7.png"]; UIImage *selectImage = [UIImage imageNamed:@"8.png"]; secVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"朋友圈" image:image selectedImage:selectImage] autorelease]; ThirdViewController *thirdVC = [[ThirdViewController alloc] init]; UINavigationController *thirdNAVC = [[UINavigationController alloc] initWithRootViewController:thirdVC]; thirdVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"设置" image:[UIImage imageNamed:@"9.png"] tag:1001] autorelease]; ForthViewController *fourthVC = [[ForthViewController alloc] init]; UINavigationController *foutthNAVC = [[UINavigationController alloc] initWithRootViewController:fourthVC]; fourthVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1002]; FivthViewController *fifthVC = [[FivthViewController alloc] init]; UINavigationController *fifthNAVC = [[UINavigationController alloc] initWithRootViewController:fifthVC]; fifthVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1003]; SixthViewController *sixthVC = [[SixthViewController alloc] init]; UINavigationController *sixthNAVC = [[UINavigationController alloc] initWithRootViewController:sixthVC]; sixthVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1004]; #pragma mark 按钮创建好,然后创建一个UITabbarController让所有的按钮显示出来 UITabBarController *tabVC = [[UITabBarController alloc] init];// tabbarController通过一个数组来管理所有要显示出来的naVC tabVC.viewControllers = @[firstNAVC, secNAVC, thirdNAVC, foutthNAVC, fifthNAVC, sixthNAVC]; self.window.rootViewController = tabVC; firstVC.tabBarItem.badgeValue = @"+99";// 对tabbar进行外观设置 tabVC.tabBar.translucent = NO;// 背景颜色 tabVC.tabBar.barTintColor = [UIColor purpleColor];// 点击之后的颜色 tabVC.tabBar.tintColor = [UIColor greenColor]; // 设置代理人 tabVC.delegate = self; tabVC.selectedIndex = 0; // 释放 [tabVC release]; [firstNAVC release]; [firstVC release]; [secNAVC release]; [secVC release]; [thirdNAVC release]; [thirdVC release]; [fourthVC release]; [foutthNAVC release]; [fifthNAVC release]; [fifthVC release]; [sixthNAVC release]; [sixthVC release]; return YES;}// 点击tabBar- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ viewController.tabBarItem.badgeValue = nil;}
#import "FirstViewController.h"@interface FirstViewController ()<UITableViewDataSource, UITableViewDelegate>@property(nonatomic, retain)NSMutableArray *arr;@end@implementation FirstViewController- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.arr = [NSMutableArray arrayWithObjects:@"宋江", @"卢俊义", @"吴用", @"公孙胜", @"关胜", @"林冲", @"秦明" ,@"呼延灼" , @"花荣",@"柴进", @"李应", @"朱仝",@"鲁智深",@"武松",nil]; } return self;}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor cyanColor]; self.navigationController.navigationBar.translucent = NO; UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64 - 49) style:UITableViewStylePlain]; [self.view addSubview:tableView]; [tableView release]; tableView.delegate = self; tableView.dataSource = self; }- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.arr.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *reuse = @"reuse"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse]; if (!cell) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse] autorelease]; UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(click:)]; [cell addGestureRecognizer:longPress]; [longPress release]; // 在这里创建的对象能重用// UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];// [button setTitle:@"测试" forState:UIControlStateNormal];// [cell addSubview:button];// button.frame = CGRectMake(300, 0, 100, 40); } cell.textLabel.text = self.arr[indexPath.row]; return cell;}- (void)click:(UILongPressGestureRecognizer *)longPress{// 通过手势,找到手势所添加的cell UITableViewCell *cell = (UITableViewCell *)longPress.view; // 创建一个快捷菜单,单例 UIMenuController *menu = [UIMenuController sharedMenuController]; // 给这个快捷菜单进行定位 [menu setTargetRect:cell.frame inView:cell.superview];// 让菜单显示出来 [menu setMenuVisible:YES animated:YES]; // 如果想使用自定义的功能 UIMenuItem *flag = [[UIMenuItem alloc] initWithTitle:@"测试" action:@selector(flag)]; // 把这个按钮放到快捷菜单上 [menu setMenuItems:@[flag]];// 按钮的方法必须要实现,无论系统还是自定义,如果不实现对应的方法,不会添加到快捷菜单上 }- (void)flag{ NSLog(@"11");}#pragma mark 快捷菜单捆绑了一个方法,这个方法必须实现,如果不实现,快捷菜单没有办法显示- (BOOL)canBecomeFirstResponder{ return YES;}// 系统自定义的快捷菜单按钮//- (void)delete:(id)sender//{// NSLog(@"删除");//}////- (void)copy:(id)sender//{// NSLog(@"复制");//}////- (void)select:(id)sender//{// NSLog(@"选择");//}
0 0
- UITabBar
- UITabBar
- UITabBar
- UITabbar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- 自定义UITabBar
- 隐藏UITabBar
- 定制 UItabbar
- Custom UITabBar
- UITabBar&UINavigation
- 隐藏 UITabBar
- 生产者消费者模型实现<二>真实实现BlockingQueue
- 通过Oracle的email实现数据库自动告警
- 不能输掉微笑
- Memset中无穷大常量的设定技巧
- MPEG DASH简析
- UITabBar
- Hdu2647 逆向拓扑_发奖金
- ubuntu 14.04系统 安装搜狗输入法
- 新手须知 C、C++和VC++之间的区别
- qsort和sort的区别
- NavigationViewController 返回到根视图
- TCL: LIST命令-lsearch, lsort, lrange
- Linux Command Line 详细解析
- Myeclipse 变量高亮问题