UITabBarController 简单例子

来源:互联网 发布:java语言入门培训班 编辑:程序博客网 时间:2024/05/21 21:38

这里做个记录以免以后忘记。

例子:http://download.csdn.net/detail/qqmcy/6916253

首先,创建UITabBarController类的对象。

ViewController.h

#import <UIKit/UIKit.h>@interface ViewController : UIViewController<UITabBarControllerDelegate>@property (strong , nonatomic) UITabBarController* m_tabBarVC;@end

ViewController.m

- (void)viewDidLoad{    [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.    self.m_tabBarVC = [[UITabBarController alloc] init];    self.m_tabBarVC.delegate = self;        OrangeViewController* orangeVC = [[OrangeViewController alloc] initWithStyle:UITableViewStylePlain];    RedViewController*    redVC = [[RedViewController alloc] initWithNibName:@"RedViewController" bundle:nil];    self.m_tabBarVC.viewControllers = @[redVC,orangeVC];    //self.m_tabBarVC.view.frame = CGRectMake(0, 0, 320, <#CGFloat height#>)    [self.view addSubview:self.m_tabBarVC.view];}

OrangeViewController.m

UITabBarItem* item = [[UITabBarItem alloc] initWithTitle:@"2" image:[UIImage imageNamed:@"changmen.jpg" ] tag:2];        self.tabBarItem = item;


0 0
原创粉丝点击