iOS基础控件-UIToolBar 导航控制器的重要属性-工具栏

来源:互联网 发布:淘宝没有高仿手表 编辑:程序博客网 时间:2024/06/15 04:26

<XSRootViewController.m>
/*
                    **UIToolBar的使用**
 
 ** UINavigationController
有一个toolBar属性
 
 ** UIToolBar
继承与UIView
 
 ** UINavigationController
底部工具栏默认处于掩藏状态
 
 **
每个是同控制器可以通过toolBarItems属性来定制toolBar
 
                   
 
                    **UIToolBar
常用属性**
 
 
 @property(nonatomic)        UIBarStyle barStyle;    // default is UIBarStyleDefault (blue)
 @property(nonatomic,copy)   NSArray   *items;       // get/set visible UIBarButtonItem. default is nil. changes not animated. shown in order
 
 
 
 */

- (
void)viewDidLoad
{
    [
super viewDidLoad];
// Do any additional setup after loading the view.
   
self.view.backgroundColor= [UIColorredColor];
    [
self.navigationItemsetTitle:@"显示工具栏"];
   
   
//显示工具栏
   
//self.navigationController.toolbarHidden = NO;
   
//显示工具栏并伴有动画
    [
self.navigationControllersetToolbarHidden:NOanimated:YES];
   
   
   
   
   
/*
    //
设置toolbar的背景图片,
    //forToolbarPosition  
     toolbar
位置,UIBarPositionAny = 0,
    
     UIBarPositionBottom = 1,
           
            // The bar is at the bottom of its local context, and directional decoration draws accordingly (e.g., shadow above the bar).
    
     UIBarPositionTop = 2,
           
            // The bar is at the top of its local context, and directional decoration draws accordingly (e.g., shadow below the bar)
    
     UIBarPositionTopAttached = 3,
           
            // The bar is at the top of the screen (as well as its local context), and its background extends upward—currently only enough for the status bar.
    
    
    
     barMetrics 
工具栏的度量
       
        UIBarMetricsDefault, 
默认(竖屏)
        UIBarMetricsLandscapePhone, 
风景模式(横屏)
        UIBarMetricsDefaultPrompt = 101, // Applicable only in bars with the prompt property, such as UINavigationBar and UISearchBar
        UIBarMetricsLandscapePhonePrompt,
     */

    [
self.navigationController.toolbarsetBackgroundImage:[UIImageimageNamed:@"composeiconbg@2x.png"]forToolbarPosition:UIBarPositionAnybarMetrics:UIBarMetricsDefault];
   
   
   
   
//通过toolBarItems来定制工具栏的显示,数组中方的时UIBarButtonItem实例
   
//@property (nonatomic, retain) NSArray *toolbarItems NS_AVAILABLE_IOS(3_0);
   
   
   
UIBarButtonItem*btnItem1 = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAddtarget:selfaction:nil];
   
   
   
UIBarButtonItem*btnItem2 = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarkstarget:selfaction:nil];
   
   
   
//item的间隔,间隔是自动算出来的
   
UIBarButtonItem*spaceItem = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:selfaction:nil];
   
   
NSArray *array = [[NSArrayalloc]initWithObjects:btnItem1,spaceItem,btnItem2,nil];
   
   
   
//通过toolbarItems来定制工具栏的显示,数组中方的是UIButtonItem实例
   
self.toolbarItems= array;
   
   
   
   
}
0 0