gpt4 book ai didi

ios - 从图像创建的导航栏按钮项背后的奇怪背景

转载 作者:行者123 更新时间:2023-11-28 22:31:48 26 4
gpt4 key购买 nike

只是尝试从图像向导航栏添加按钮。

代码:

UIBarButtonItem *newConvoButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"convos_new.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(newConvoInit:)];
self.navigationItem.rightBarButtonItem = newConvoButton;

结果:

1(应该只是背景中没有蓝色按钮的深色图像。)

最佳答案

对于您想要的东西,这可能有点矫枉过正。但我有一种很好的感觉,这会让你的生活变得更轻松。以下将只为您提供一个没有任何 UIBarButtonItem 属性的图像。

UIImage *menuImage = [UIImage imageNamed:@"navBarMenuButton.png"];
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton.frame = CGRectMake(0, 0, menuImage.size.width, menuImage.size.height);
[leftButton setBackgroundImage:menuImage forState:UIControlStateNormal];
aController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];

这个方法实现了一个自定义的 UIButton,给定了你正在使用的 UIImage 的框架,除了你选择的图像添加到你的UINavigationBar.

好处是您不必担心重新调整任何东西的大小以防将来图像发生变化,因为框架继承自 UIImage

祝你好运!

关于ios - 从图像创建的导航栏按钮项背后的奇怪背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17200456/

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