您的位置:首页 > 产品设计 > UI/UE

iOS UI11_UITabBar

2015-08-13 08:39 417 查看
//
//  AppDelegate.m
//  UI11_UITabBar
//
//  Created by dllo on 15/8/12.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourViewController.h"
#import "FiveViewController.h"
#import "SixViewController.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];
firstVC.tabBarItem.badgeValue =@"+99";

//创建第二个
SecondViewController *secondVC = [[SecondViewController alloc] init];
UINavigationController *secondNAVC=[[UINavigationController alloc] initWithRootViewController:secondVC];
secondVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"保护费" image:[UIImage imageNamed:@"iconfont-jiaofei.png"] selectedImage:[UIImage imageNamed:@"iconfont-chongzhi.png"]];

ThirdViewController *thirdVC=[[ThirdViewController alloc] init];
UINavigationController *thirdNAVC=[[UINavigationController alloc] initWithRootViewController:thirdVC];
thirdVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"进账" image:[UIImage imageNamed:@"iconfont-jiaofei.png"] tag:1000];

FourViewController *fourVC=[[FourViewController alloc] init];
UINavigationController *fourNAVC=[[UINavigationController alloc] initWithRootViewController:fourVC];
fourVC.tabBarItem=[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1000];

FiveViewController *fiveVC=[[FiveViewController alloc] init];
UINavigationController *fiveNAVC=[[UINavigationController alloc] initWithRootViewController:fiveVC];
fiveVC.tabBarItem=[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1000];

SixViewController *sixVC=[[SixViewController alloc] init];
UINavigationController *sixNAVC=[[UINavigationController alloc] initWithRootViewController:sixVC];
sixVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1000];

#pragma mark 按钮创建好,然后创建一个UITabbarController让所有的按钮显示出来
UITabBarController *tabVC = [[UITabBarController alloc] init];
//UITabBarController通过一个数组来管理所有要显示出来的naVC
tabVC.viewControllers = @[firstNAVC,secondNAVC,thirdNAVC,fourNAVC,fiveNAVC,sixNAVC];
self.window.rootViewController = tabVC;

//对tabBar进行外观设置
tabVC.tabBar.translucent =NO;
//背景颜色
tabVC.tabBar.barTintColor=[UIColor orangeColor];
//点击之后图片颜色
tabVC.tabBar.tintColor=[UIColor yellowColor];
//先签订协议,设置代理人
tabVC.delegate=self;
//选第几个页面
//    tabVC.selectedIndex = 1;

//内存管理
[tabVC release];
[firstVC release];
[firstNAVC release];
[secondVC release];
[secondNAVC release];
[thirdVC release];
[thirdNAVC release];
[fourNAVC release];
[fourVC release];
[fiveVC release];
[fiveNAVC release];
[sixNAVC release];
[sixVC release];

return YES;
}
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
viewController.tabBarItem.badgeValue =nil;
}

- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end


//
//  FirstViewController.m
//  UI11_UITabBar
//
//  Created by dllo on 15/8/12.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import "FirstViewController.h"

@interface FirstViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)NSMutableArray *arr;
@property(nonatomic,retain)UITableView *tableView;
@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 yellowColor];
self.navigationController.navigationBar.translucent=NO;

self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64-49) style:UITableViewStylePlain];
[self.view addSubview:self.tableView];
self.tableView.delegate=self;
self.tableView.dataSource=self;
[self.tableView release];

}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(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:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(click:)];
[cell addGestureRecognizer:longPress];
[longPress release];

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(250, 0, 100, 30);
[button setTitle:@"测试" forState:UIControlStateNormal];
button.layer.borderWidth = 1;
button.layer.cornerRadius = 10;
[cell addSubview:button];

}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]];
//按钮方法必须实现,无论系统还是自定义,如果不实现对应的方法,不会添加到快捷菜单

}
#pragma mark 快捷菜单捆绑了一个方法,这个方法必须实现,如果不事先,快捷菜单没有办法显示
-(BOOL)canBecomeFirstResponder
{
return YES;
}
//-(void)delete:(id)sender
//{
//    NSLog(@"删除");
//}
//-(void)copy:(id)sender
//{
//    NSLog(@"复制");
//}
//-(void)select:(id)sender
//{
//    NSLog(@"选择");
//}
//写自定义的
-(void)flag
{
NSLog(@"faf");
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: