【发布时间】:2010-08-17 19:42:18
【问题描述】:
我有一个使用我自己的背景图像自定义的 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
非常感谢任何帮助!
【问题讨论】:
标签: iphone uibarbuttonitem uitoolbar