How to place UIBarButtonItem on the right side of a UIToolbar?

前端 未结 6 1461
故里飘歌
故里飘歌 2020-12-14 00:39

I have designed a view with a toolbar that appears modally in Interface Builder. I have a UIBarButtonItem that is on the left hand side, which I would like to appear on the

6条回答
  •  囚心锁ツ
    2020-12-14 01:11

    Here's how to do it in code if anyone comes across this post:

    UIBarButtonItem *leftButton = [[[UIBarButtonItem alloc] initWithTitle:@"Item" style:UIBarButtonItemStyleBordered target:self action:@selector(btnItem1Pressed:)] autorelease];
    
    UIBarButtonItem *flex = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil] autorelease];
    
    UIBarButtonItem *rightButton = [[[UIBarButtonItem alloc] initWithTitle:@"Item" style:UIBarButtonItemStyleBordered target:self action:@selector(btnItem2Pressed:)] autorelease];
    
    
    self.toolbarItems = [NSArray arrayWithObjects: leftButton, flex, rightButton, nil];
    

提交回复
热议问题