中文字幕一区二区人妻电影,亚洲av无码一区二区乱子伦as ,亚洲精品无码永久在线观看,亚洲成aⅴ人片久青草影院按摩,亚洲黑人巨大videos

iOS工具欄

工具欄的使用

我們可以使用工具欄修改視圖元素。

如,郵件應(yīng)用程序里的收件箱欄中有刪除、分享、答復(fù)等等。如下所示:

toolbar

重要的屬性

  • barStyle
  • items

添加自定義方法?addToolbar

-(void)addToolbar
{
    UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] 
    initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
    target:nil action:nil];
    UIBarButtonItem *customItem1 = [[UIBarButtonItem alloc]
    initWithTitle:@"Tool1" style:UIBarButtonItemStyleBordered 
    target:self action:@selector(toolBarItem1:)];
    UIBarButtonItem *customItem2 = [[UIBarButtonItem alloc]
    initWithTitle:@"Tool2" style:UIBarButtonItemStyleDone 
    target:self action:@selector(toolBarItem2:)];
    NSArray *toolbarItems = [NSArray arrayWithObjects: 
    customItem1,spaceItem, customItem2, nil];
    UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:
    CGRectMake(0, 366+54, 320, 50)];
    [toolbar setBarStyle:UIBarStyleBlackOpaque];
    [self.view addSubview:toolbar];
    [toolbar setItems:toolbarItems];
}

為了解所執(zhí)行的操作我們?cè)谖覀兊腣iewController.xib中添加UILabel Iboutlet并為?UILabel?創(chuàng)建命名為標(biāo)簽的IBoutlet。

我們還需要添加兩個(gè)方法來執(zhí)行,如下所示的工具欄項(xiàng)的操作:

-(IBAction)toolBarItem1:(id)sender{
    [label setText:@"Tool 1 Selected"];
}

-(IBAction)toolBarItem2:(id)sender{
    [label setText:@"Tool 2 Selected"];    
}

在ViewController.m中更新?viewDidLoad,如下所示:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // The method hideStatusbar called after 2 seconds
    [self addToolbar];    
    // Do any additional setup after loading the view, typically from a nib.
}

輸出

現(xiàn)在當(dāng)我們運(yùn)行該應(yīng)用程序我們會(huì)看到下面的輸出。

toolbarOutput

單擊我們得到的?tool1?和?tool2?欄按鈕

toolbarActionOutput

其他擴(kuò)展