相关疑难解决方法(0)

UIBarButtonItem具有自定义图像,没有边框

我想用自定义图像创建一个UIBarButtonItem,但我不想要iPhone添加的边框,因为我的图像有一个特殊的边框.

它与后退按钮相同,但是前进按钮.

这个应用程序是针对inHouse项目的,所以我不在乎Apple是拒绝或批准它还是喜欢它:-)

如果我使用UIBarButtonItem的initWithCustomView:v属性,我可以这样做:

UIImage *image = [UIImage imageNamed:@"right.png"];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage: [image stretchableImageWithLeftCapWidth:7.0 topCapHeight:0.0] forState:UIControlStateNormal];
[button setBackgroundImage: [[UIImage imageNamed: @"right_clicked.png"] stretchableImageWithLeftCapWidth:7.0 topCapHeight:0.0] forState:UIControlStateHighlighted];

 button.frame= CGRectMake(0.0, 0.0, image.size.width, image.size.height);

[button addTarget:self action:@selector(AcceptData)    forControlEvents:UIControlEventTouchUpInside];

UIView *v=[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, image.size.width, image.size.height) ];

[v addSubview:button];

UIBarButtonItem *forward = [[UIBarButtonItem alloc] initWithCustomView:v];

self.navigationItem.rightBarButtonItem= forward;

[v release];
[image release];
Run Code Online (Sandbox Code Playgroud)

这有效,但如果我必须在10个视图中重复此过程,这不是DRY.

我想我必须继承,但是什么?

  • NSView?
  • UIBarButtonItem?

谢谢,

问候,

iphone uibarbuttonitem ios

88
推荐指数
5
解决办法
7万
查看次数

标签 统计

ios ×1

iphone ×1

uibarbuttonitem ×1