UITabBar 使用

来源:互联网 发布:安特托孔波数据 编辑:程序博客网 时间:2024/06/05 16:23
[java] view plaincopy
  1. UITabBar* tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(40,0.0,240,70)];  
  2.     [tabBar setBackgroundImage:[UIImage imageNamed:@"titlebarbg.png"]];  
  3.     UITabBarItem * tabBarItem1 = [[UITabBarItem alloc] initWithTitle:@"人数" image:nil tag:0];  
  4.     UITabBarItem * tabBarItem2 = [[UITabBarItem alloc] initWithTitle:@"人均" image:nil tag:1];  
  5.     UITabBarItem * tabBarItem3 = [[UITabBarItem alloc] initWithTitle:@"距离" image:nil tag:2];  
  6.     UITabBarItem * tabBarItem4 = [[UITabBarItem alloc] initWithTitle:@"好评" image:nil tag:3];  
  7.     NSArray *tabBarItemArray = [[NSArray alloc] initWithObjects: tabBarItem1, tabBarItem2, tabBarItem3, tabBarItem4,nil];  
  8.     [tabBar  setItems: tabBarItemArray];  
  9.     tabBar.delegate =self;  
  10.   
  11. - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item  
  12. {  
  13.     NSLog(@"itemClick: %d",item.tag);  
  14. }  
   头文件中实现:

@interface ViewController : UIViewController<UITabBarDelegate>