0

So I have a UIToolbar which has a custom height (which I set by overriding UIToolbar's -sizeThatFits. I want to position my UIBarButtonItems higher in the tool bar. I do so by overriding -layoutSuviews as such:

-(void)layoutSubviews
{
    [super layoutSubviews];
    for(UIBarButtonItem* item in self.items)
    {

        UIView *view;
        @try {
            view = [item valueForKey:@"view"];
        }
        @catch (NSException *exception) {    NSLog(@"%@", exception.reason);  }

        view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height-33);
        }
    }
}

This works fine for bar buttons made with -initWithBarButtonSystemItem:, however it has no effect on bar buttons that I've made with -initWithCustomView: or -initWithTitle:.

Should I be using something different in [item valueForKey:@"view"], or is there a different way?

4

1 回答 1

0

从来没有想出这个问题的崇高答案。我通过向自定义栏按钮项添加开关等来解决我的需求。

于 2013-10-25T08:32:24.297 回答