在 UIToolbar 之间添加间距

发布于 2024-11-25 18:58:17 字数 852 浏览 3 评论 0原文

我有一个如下所示的工具栏:

在此处输入图像描述

问题是它有点混乱,因此我想为其添加一些间距。我尝试这样做:

UIBarButtonItem *spacer = 
 [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
                                               target:nil 
                                               action:nil];

self.toolbar_array = 
 [[NSMutableArray alloc] initWithObjects:self.mention, 
                                         spacer, 
                                         self.picture, 
                                         spacer, 
                                         share, 
                                         spacer, 
                                         self.message, nil];

但它仍然给了我同样的东西。如何在这些 UIBarButtonItems 之间添加 10px?

I have a toolbar that looks like the following:

enter image description here

The issue is that it is kind of cluttered and therefore I would like to add some spacing to it. I tried doing:

UIBarButtonItem *spacer = 
 [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
                                               target:nil 
                                               action:nil];

self.toolbar_array = 
 [[NSMutableArray alloc] initWithObjects:self.mention, 
                                         spacer, 
                                         self.picture, 
                                         spacer, 
                                         share, 
                                         spacer, 
                                         self.message, nil];

But it still gives me the same thing. How can I add a 10px between these UIBarButtonItems?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

呢古 2024-12-02 18:58:17
UIBarButtonItem *fixedSpace = 
  [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace 
                                                target:nil 
                                                action:nil];
fixedSpace.width = 10;
UIBarButtonItem *fixedSpace = 
  [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace 
                                                target:nil 
                                                action:nil];
fixedSpace.width = 10;
挽清梦 2024-12-02 18:58:17

您需要在您要查找的项目之间添加空格。
这可以通过..

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.

还如梦归 2024-12-02 18:58:17

我使用此代码生成 UIBarButtonItems,它是一些头文件,如果需要,我会#import。

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];
}

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文