Add spacing between UIToolbar

巧了我就是萌 提交于 2019-12-03 09:58:48
Joe
UIBarButtonItem *fixedSpace = 
  [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace 
                                                target:nil 
                                                action:nil];
fixedSpace.width = 10;

You need to add space in between the items what u r looking for. this can be done by..

UIBarButtonItem *fixedSpace = 
 [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace 
                                               target:nil 
                                               action:nil];
fixedSpace.width = 10;

hope this will help u.

Christian Schnorr

I use this code to generate UIBarButtonItems, it's some header file which I #import if needed.

static inline UIBarButtonItem *BarButtonWithText(NSString *text, 
                                                 id target, 
                                                 SEL action) {
    NSString *localizedText = NSLocalizedString(text, nil);
    return [[[UIBarButtonItem alloc] initWithTitle:localizedText 
                                             style:UIBarButtonItemStyleBordered 
                                            target:target 
                                            action:action] autorelease];
}

static inline UIBarButtonItem *BarButtonWithImage(NSString *imageName, 
                                                  id target, 
                                                  SEL action) {
    UIImage *image = [UIImage imageNamed:imageName];
    return [[[UIBarButtonItem alloc] initWithImage:image 
                                             style:UIBarButtonItemStylePlain 
                                            target:target 
                                            action:action] autorelease];
}

static inline UIBarButtonItem *BarButtonWithSystemStyle(UIBarButtonSystemItem style, 
                      id target, 
                      SEL action) {
    return [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:style 
                                                          target:target 
                                                          action:action] autorelease];
}

static inline UIBarButtonItem *BarButtonWithFlexibleWidth(id target, SEL action) {
    return [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
                                                          target:target 
                                                          action:action] autorelease];
}

static inline UIBarButtonItem *BarButtonWithFixedWidth(CGFloat width, 
                                                       id target, 
                                                       SEL action) {
    UIBarButtonItem *button = 
      [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace 
                                                    target:target 
                                                    action:action];
    button.width = width;
    return [button autorelease];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!