How to add custom image in navigation bar button item?

前端 未结 12 1691
我寻月下人不归
我寻月下人不归 2020-12-13 09:26
 UIBarButtonItem *doneitem=[[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed:)]autorelease];
           


        
12条回答
  •  無奈伤痛
    2020-12-13 10:09

    Try this code:

    UIImage* image3 = [UIImage imageNamed:@"mail-48_24.png"];
    CGRect frameimg = CGRectMake(0, 0, image3.size.width, image3.size.height);
    UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg];
    [someButton setBackgroundImage:image3 forState:UIControlStateNormal];
    [someButton addTarget:self action:@selector(sendmail)
         forControlEvents:UIControlEventTouchUpInside];
    [someButton setShowsTouchWhenHighlighted:YES];
    
    UIBarButtonItem *mailbutton =[[UIBarButtonItem alloc] initWithCustomView:someButton];
    self.navigationItem.rightBarButtonItem=mailbutton;
    [someButton release];
    

提交回复
热议问题