简体   繁体   中英

info light button in navigation bar

How can I change this code so I have an info button in the right corner of the navigation bar instead of a word?

- (void)viewDidLoad {
   [self setTitle:@"About"];
   [super viewDidLoad];
   UIBarButtonItem *addButton = [[[UIBarButtonItem alloc]   initWithTitle:NSLocalizedString(@"info", @"")
                                                            style:UIBarButtonItemStyleBordered
                                                            target:self
                                                            action:@selector(addAction:)] autorelease];
   self.navigationItem.rightBarButtonItem = addButton;  
}

This question has often been asked.

        UIImage *buttonImage = [UIImage imageNamed:@"UIButtonInformationIcon.jpg"]; 
        //create the button and assign the image
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:buttonImage forState:UIControlStateNormal];
        //set the frame of the button to the size of the image
        button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);

        [button addTarget:self action:@selector(anyActionYouWant) forControlEvents:UIControlEventTouchUpInside]; 
        //create a UIBarButtonItem with the button as a custom view

        self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button]autorelease];  

Here's one solution, among several.

Or... you could select from the drop-down list when adding a button to the title bar, which kind of button you want. You'd need to select the type "Info Light".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM