gpt4 book ai didi

ios - 具有自定义图像且无边框的 UIBarButtonItem

转载 作者:IT王子 更新时间:2023-10-29 07:30:12 24 4
gpt4 key购买 nike

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

它与后退按钮相同,但它是一个前进按钮。

这个应用程序是一个内部项目,所以我不在乎 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];

这可行,但如果我必须在 10 个 View 中重复此过程,这不是 DRY。

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

  • NSView ?
  • UIBarButtonItem ?

谢谢,

问候,

最佳答案

另一个简单的解决方案是

  1. 拖一个标准的 UIButton
  2. 将按钮的样式设置为自定义并为该按钮设置您的图像
  3. 将它拖到 UINavigationBar 上
  4. 设置选择器

关于ios - 具有自定义图像且无边框的 UIBarButtonItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2681321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com