gpt4 book ai didi

ios - 试图将自定义 UIBarButtonItem 添加到 UIToolBar,但项目搞砸了

转载 作者:行者123 更新时间:2023-11-28 18:37:26 25 4
gpt4 key购买 nike

我正在尝试向我的 UIToolBar 添加一个自定义按钮(形状和颜色),但结果与预期的大不相同。

按钮的样子:

enter image description here

它在酒吧里的样子:

enter image description here

这是我用来添加它的代码:

    UIImage *backButtonImage = [UIImage imageNamed:@"back-button.png"];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:backButtonImage style:UIBarButtonItemStylePlain target:self action:@selector(backButtonTapped)];
[toolBarItems addObject:backButton];

我到底做错了什么?

最佳答案

尝试使用 initWithCustomView: 而不是其他初始化方法

所以你应该首先用你想要的自定义图像和选择器创建一个 UIButton 然后使用这段代码

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:yourButton];
[toolBarItems addObject:backButton];

关于ios - 试图将自定义 UIBarButtonItem 添加到 UIToolBar,但项目搞砸了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16270601/

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