0

iOS,如何制作一个没有边框、没有跨度的自定义uibarbuttonitem?

喜欢这张照片吗?

在此处输入图像描述

我不知道如何命名这种风格。所有这些按钮都在 UIToolBar 组件上。

非常感谢你。

4

1 回答 1

1

根据我的理解,在这种情况下最好使用段控制器,但如果你不想使用它,你可以通过以下方式将图像应用到你的栏按钮。

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];

希望这对您有所帮助。谢谢。

于 2012-10-17T05:56:08.260 回答