gpt4 book ai didi

ios - UIBarButtonItem 在 UIToolBar 和 UINavigationBar 中的显示方式不同

转载 作者:行者123 更新时间:2023-12-01 19:19:55 25 4
gpt4 key购买 nike

我需要在 UIToolBar 中使用一个简单的 UIBarButtonItem。

我使用此代码将带有自定义图像的按钮添加到导航栏:

UIBarButtonItem *cloneButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"image_sheep.png"] style:UIBarButtonItemStylePlain target:self action:@selector(clone)];
NSArray *rightItems = [NSArray arrayWithObject:cloneButton];
self.navigationItem.rightBarButtonItems = rightItems;

结果是我想要的,它看起来像这样

navigation bar http://img207.imageshack.us/img207/3383/navigationbara.jpg

在我添加到 UITableViewCell 的 contentView 的 UIToolBar 中做同样的事情时
UIBarButtonItem *cloneButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"image_sheep.png"] style:UIBarButtonItemStylePlain target:self action:@selector(clone)];
UIBarButtonItem *leftSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
toolbar.items = [NSArray arrayWithObjects:leftSpace, cloneButton, nil];

问题是我得到这样的东西:

toolbar http://img209.imageshack.us/img209/1374/toolbary.jpg

这肯定是因为 UINavigationBar 和 UIToolBar 的绘制方式不同......
有人可以指出如何解决这个问题吗?

最佳答案

在您的 UIToolbar 上使用 UIBarButtonItemStyleBordered 而不是 UIBarButtonItemStylePlain .
UINavigationBar不会在没有按钮外观的情况下绘制相同的按钮。

关于ios - UIBarButtonItem 在 UIToolBar 和 UINavigationBar 中的显示方式不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10812015/

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