How to add bar buttons in a UIToolBar

后端 未结 2 428
清歌不尽
清歌不尽 2021-01-22 20:47

I have created a UIToolBar and want to add three items in that like contact, date and message. I tried but i am not able to do that.Kindly help as i am new to

2条回答
  •  渐次进展
    2021-01-22 21:10

    try this...

    UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
        myToolbar.barStyle = UIBarStyleBlackOpaque;
    
        UIBarButtonItem *flexibleSpaceLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    
        UIBarButtonItem *contactBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(contact:)];
    
    UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    
     UIBarButtonItem *dateBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(date:)];
    
    UIBarButtonItem *flexibleSpaceRight = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    
     UIBarButtonItem *msgBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(message:)];
    
    [myToolbar setItems:[NSArray arrayWithObjects: flexibleSpaceLeft, doneBtn, flexibleSpace, dateBtn, flexibleSpaceRight, msgBtn, nil]];
    

提交回复
热议问题