【UIKit】TabView

 

【TabView】

 

 

【下面的tab栏】【code

【第一步】:创建一个Tabbed Application 

     

【第二步】:加入图片素材。

【第三步】:创建3个有xib的类文件 FirstViewController,SecondViewController,ThirdViewController。

     

【第四步】:分别在FirstViewController,SecondViewController,ThirdViewController中加入下面的代码

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; // 固定写法
    if (self) {
        self.title = NSLocalizedString(@"关于我们", @"关于我们");   // 这个是加入标题,显示的标题
        self.tabBarItem.image = [UIImage imageNamed:@"first"];   // 显示自己图片包中的对应的图片
    }
    return self;
}

【第五步】:声明窗口和代理方法

// 应用程序委托
@interface AppDelegate : UIResponder <UIApplicationDelegate>

// 窗口
@property (strong, nonatomic) UIWindow *window;

// 根视图控制器
@property (nonatomic,retain) UITabBarController *tabController;

【第六步】完善代码

// 视图加载完成,应用程序加载到内存后调用的方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // 创建窗口
    self.window=[[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds] autorelease];

    // 创建3个视图控制器
    FirstViewController *viewController1=[[FirstViewController alloc] initWithNibName:nil bundle:nil];
    SecondViewController *viewController2=[[SecondViewController alloc] initWithNibName:nil bundle:nil];
    ThirdViewController *viewController3=[[ThirdViewController alloc] initWithNibName:nil bundle:nil];
    
    // 把根视图控制器作为窗口的 第一个视图控制器
    self.tabController=[[UITabBarController alloc] init];
    self.tabController.viewControllers=@[viewController1,viewController2,viewController3];
    
    
    self.window.rootViewController=self.tabController;
    // 显示窗口
    [self.window makeKeyAndVisible];
    
    [viewController1 release];
    [viewController2 release];
    [viewController3 release];
    
    return YES;
}

 

 


 

 

【创建有状态栏的】【Code

【增加状态栏】:增加前与增加后插入代码【Code

    

【第三方加入状态标栏】:引入第三方库【Code

其他详见代码。

 // 计算当前高度

    CGFloat cellHeight = [tableView rectForRowAtIndexPath:indexPath].size.height;

 

posted @ 2014-04-20 17:55  太过于漂流  阅读(297)  评论(0编辑  收藏  举报