How to make a UIBarButtonItem like this

后端 未结 3 1389
無奈伤痛
無奈伤痛 2021-01-14 14:39

How can I make a UIBarButtonItem like this: \"enter

I can\'t find it in the SystemItem

相关标签:
3条回答
  • 2021-01-14 15:05

    Swift's version of @Jhaliya's answer for quick copy-paste:

    let infoButton = UIButton(type: .InfoLight)
    
    infoButton.addTarget(self, action: "InfoButtonClicked:", forControlEvents: .TouchUpInside)
    
    let infoBarButtonItem = UIBarButtonItem(customView: infoButton)
    
    navigationItem.rightBarButtonItem = infoBarButtonItem
    
    0 讨论(0)
  • 2021-01-14 15:08

    That's probably using something like:

    [[UIBarButtonItem alloc] initWithImage:@"info.png" style:UIBarButtonItemStyleBordered target:nil action:nil]
    

    I tried with:

    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeInfoLight]];
    item.style = UIBarButtonItemStyleBordered;
    

    but it seems like with a custom view the bordered style doesn't get applied.

    0 讨论(0)
  • 2021-01-14 15:10

    The Image button which you have called info button.It's an system button,

    Use below to get it as your rightBarButtonItem

    UIButton* myInfoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
    [myInfoButton addTarget:self action:@selector(InfoButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myInfoButton];
    

    Here is the documentation link to UIButtonType

    0 讨论(0)
提交回复
热议问题