iOS UIBarButtonItem对齐 [英] iOS UIBarButtonItem alignments

查看:98
本文介绍了iOS UIBarButtonItem对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我添加了两个带导航栏的UIBarButtonItem。在iOS6及以下版本中,它看起来像这样

In my app I added two UIBarButtonItem with navigation bar. In iOS6 and below it looks like this

但是当我在iOS7中运行我的应用程序时,它看起来像

But when I run my app in iOS7 it looks like

问题是:刷新按钮下降。所以请帮我显示等于'今天'按钮的刷新按钮。下面是我正在使用的代码,

issue is: refresh button goes down. So please help me to display refresh button equal to 'today' button. Below is the code I'm using ,

 UIBarButtonItem* todayButton = [[UIBarButtonItem alloc] initWithTitle:@"Today"
                                                                style:UIBarButtonItemStyleBordered 
                                                               target:self
                                                               action:@selector(showTodayAction:)];
UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                                              target:self
                                                                              action:@selector(refreshAction:)];
refreshButton.style = UIBarButtonItemStyleBordered;

    UIBarButtonItem *negativeSeperator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                                       target:nil
                                                                                       action:nil];
    negativeSeperator.width = -12;

    TransparentToolbar *toolbar = [[TransparentToolbar alloc] initWithFrame:CGRectMake(0, -5, 100, TOOLBAR_HEIGHT)];
    toolbar.items = [NSArray arrayWithObjects:
                     negativeSeperator,
                     refreshButton, todayButton,
                     negativeSeperator,
                     nil];

    UIView *toolbarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, TOOLBAR_HEIGHT)];
    [toolbarView addSubview:toolbar];

    UIBarButtonItem *toolbarItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarView];

    self.navigationItem.leftBarButtonItem = toolbarItem;


推荐答案

我认为不需要其他额外的观点,以下代码将完成您的工作:

I think there is no requirement of other extra views, the following code will do your work :

UIBarButtonItem* todayButton = [[UIBarButtonItem alloc] initWithTitle:@"Today"
                                                                    style:UIBarButtonItemStyleBordered
                                                                   target:self
                                                                   action:@selector(showTodayAction:)];
    UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                                                   target:self
                                                                                   action:@selector(refreshAction:)];
    refreshButton.style = UIBarButtonItemStyleBordered;

    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:refreshButton, todayButton, nil];

这篇关于iOS UIBarButtonItem对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆