我将CustomImage UIButtons作为我的UIBarButtonItems。平面设计师制作图像的方式,它们是相互对接的,并且它们之间没有10px左右的间隙。有没有办法在将UIBarButtonItem添加到UIToolBar时消除它们之间的差距?
由于
答案 0 :(得分:1)
所以摆弄,我能够得到一些工作。虽然我不是100%肯定我理解为什么。如果我传入一个宽的图像(大于15 + px)它可以正常工作,如果我放入1px宽的图像,我就无法使它工作。我正在寻找的是:
<image> | <Image> | <image> | <flex space> | <image> | <Image> | <image>
虽然我不想创建其中包含|
的图片,但我的图片只是|
分隔符。添加Button时,我无法将它们之间的差距关闭。我摆弄框架和插入值无济于事。
这就是我对更宽按钮的要求:
-(id)initWithTitle:(NSString *)title normalImage:(UIImage *)normalImage highlightedImage:(UIImage *)highlightedImage selectedImage:(UIImage *)selectedImage target:(id)target action:(SEL)action {
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:normalImage forState:UIControlStateNormal];
[button setImage:highlightedImage forState:UIControlStateHighlighted];
[button setImage:selectedImage forState:UIControlStateSelected];
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 74, 48)];
// This is the code that seemed to make it work
// Though not 100% sure why
// - - - - -
UIEdgeInsets buttonInset = UIEdgeInsetsMake(0, -5, 0, -5);
button.contentEdgeInsets = buttonInset;
[button sizeToFit];
button.autoresizingMask = UIViewAutoresizingNone;
// - - - - -
buttonLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 74, 17)];
buttonLabel.opaque = NO;
buttonLabel.backgroundColor = [UIColor clearColor];
buttonLabel.font = [UIFont systemFontOfSize:12.0f];
buttonLabel.text = title;
buttonLabel.textAlignment = UITextAlignmentCenter;
[button addSubview:buttonLabel];
[buttonLabel release];
// create a UI
self = [super initWithCustomView:button];
[self setStyle:UIBarButtonItemStyleBordered];
return self;
}