gpt4 book ai didi

iphone - 使用自定义图像按钮命中 UIToolbar 上的目标不正确

转载 作者:行者123 更新时间:2023-12-03 20:10:24 25 4
gpt4 key购买 nike

我有一个用自己的背景图像自定义的 UIToolbar。因此,内置的 UIBarButtonItem 外观对我不起作用,因此我使用已经准备好在栏中显示的图像。我使用此方法创建一个自定义按钮项:

+ (UIBarButtonItem *)customWithImage:(UIImage *)image enabled:(BOOL)enabled target:(id)target action:(SEL)selector {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//I've tried different values for the frame here, but no luck
button.frame = CGRectMake(0, 0, 44, 44);
button.enabled = enabled;
button.showsTouchWhenHighlighted = YES;
[button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
[button setImage:image forState:UIControlStateNormal];

UIBarButtonItem *it = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
//Tried changing this, to no avail
it.width = 32.f;
return it;

我的左侧有一个按钮,右侧有一个按钮,我正在尝试这样做,以便如果您点击 UIToolbar 的最左侧或最右侧,就会点击相应的按钮。但是,使用这些自定义按钮,点击目标不会一直延伸到 UIToolbar 的边缘,而是从侧面插入:

http://skitch.com/andpoul/d1p8g/hit-targets

非常感谢任何帮助!

最佳答案

如果您使用自定义 View ,UIBarButtonItem.width 可能会被忽略(它可能只使用 View 的宽度)。

一个蹩脚的技巧是使工具栏更宽(因此它会粘在屏幕之外)并向背景图像添加透明边缘以进行补偿。这会使按钮更靠近屏幕边缘。

另一种方法是使用带有 UIButton subview 的 UIImageView。

关于iphone - 使用自定义图像按钮命中 UIToolbar 上的目标不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3506298/

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