Search code examples
iosuibarbuttonitemuitoolbaruibarbuttonitemstyle

iOS, how to make a custom uibarbuttonitem with no-border, no-span with each other? like this picture?


iOS, how to make a custom uibarbuttonitem with no-border, no-span with each other?

like this picture?

enter image description here

I do not know how to name this style. all these buttons are on the UIToolBar component.

thank you very much.


Solution

  • As per my understanding it's better to use segment-controller in such cases, But if you don't wanna use it you can apply the image to your bar buttons in following way.

    UIImage *image=[[UIImage imageNamed:@"barbuttonimage.png"] stretchableImageWithLeftCapWidth:50 topCapHeight:10];
    // Specify width & height as per your need..
    
    CGRect frameimg = CGRectMake(0, 0, image.size.width,image.size.height);
    
    UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg];
    
    [someButton setBackgroundImage:image forState:UIControlStateNormal];
    
    [someButton addTarget:self action:@selector(myBarbuttonEvent)
             forControlEvents:UIControlEventTouchUpInside];
    
     UIBarButtonItem *myBarbutton =[[UIBarButtonItem alloc] initWithCustomView:someButton];
        self.navigationItem.leftBarButtonItem=mailbutton;
    
    [someButton release];
    

    Hope this helps you. Thanks.