UITabbarController 实例一
今天用純代碼來實現(xiàn)UITabbarController的功能,不需要在xib里面使用任何控件?
本文轉(zhuǎn)自?http://www.999dh.net/article/iphone_ios_art/47.html? 轉(zhuǎn)載請注明謝謝!
1.建立一個 empty application 工程
2.在 appdelegate.h文件里面實現(xiàn)如下
@interface XYZAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (retain,nonatomic) UITabBarController * tabController;
@end
3.定義3個 viewController?? 繼承自??UIViewController??名字分別為 FirstViewController,SecondViewController,ThirdViewController ,然后分別在 每個view對應的xib文件里面拖上不同的控件(這樣做的目的是為了區(qū)分在tab 切換的時候已經(jīng)切換到了不同的view上去)
4.appdeletate.m文件里面實現(xiàn)如下
#import "XYZAppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
@implementation XYZAppDelegate
@synthesize window = _window;
@synthesize tabController;
- (void)dealloc
{
????[_window release];
????[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
????self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
????// Override point for customization after application launch.
????self.window.backgroundColor = [UIColor whiteColor];
????
????
????FirstViewController * fristView = [[FirstViewController alloc] init];
????SecondViewController* secView = [[SecondViewController alloc] init];
????ThirdViewController * thirdView = [[ThirdViewController alloc] init];
????UITableViewController * forthView = [[UITableViewController alloc] init];
????
????NSArray * array = [[NSArray alloc]initWithObjects:fristView,secView,thirdView, forthView,nil];
????
????tabController = [[UITabBarController alloc]init];
????
????tabController.viewControllers = array;
????
????[[tabController.tabBar.items objectAtIndex:0]setTitle:@"AAA"];
????[[tabController.tabBar.items objectAtIndex:1]setTitle:@"BBBB"];
????[[tabController.tabBar.items objectAtIndex:2]setTitle:@"CCCC"];
????[[tabController.tabBar.items objectAtIndex:3]setTitle:@"DDDD"];
????
????[[tabController.tabBar.items objectAtIndex:0]setImage:[UIImage imageNamed:@"001.png"]];
????[[tabController.tabBar.items objectAtIndex:1]setImage:[UIImage imageNamed:@"002.png"]];
????[[tabController.tabBar.items objectAtIndex:2]setImage:[UIImage imageNamed:@"003.png"]];
????[[tabController.tabBar.items objectAtIndex:3]setImage:[UIImage imageNamed:@"004.png"]];
????
????tabController.selectedIndex = 1;
????
????[self.window addSubview:tabController.view];
????
????
????[array release];
????
????
????[self.window makeKeyAndVisible];
????return YES;
}
實現(xiàn)后的效果如圖所示??
轉(zhuǎn)載于:https://www.cnblogs.com/rollrock/archive/2013/01/04/2843756.html
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術(shù)人生總結(jié)
以上是生活随笔為你收集整理的UITabbarController 实例一的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 实现本网站图片保护功能之加水印
- 下一篇: 博客新家(agiledon.github