美文网首页
在苹果5s导航栏右边文字按钮显示“...”

在苹果5s导航栏右边文字按钮显示“...”

作者: nadou23 | 来源:发表于2018-07-07 18:15 被阅读39次

    这个问题,主要是在苹果6以上设置了“历史记录”按钮都正常显示,宽度设置为35,而苹果5s模拟器(ios11)也没问题,所以自以为真机不会有问题,但在苹果5s iOS10以下,就出现了问题,展示“...”。而解决这个问题,一开始思路就错了,以为是ios9的问题,设置宽度无效化的问题,所以花了大量时间在查找iOS9的问题,最后发现原来是自定义的导航栏右边文字按钮的宽度不够引起的,
    看代码

    UIBarButtonItem *flexSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                                   target:self
                                                                                   action:nil];
        flexSpacer.width = -10;
        //通用保存按钮
        UIButton *right = [UIButton buttonWithType:UIButtonTypeSystem];
        right.frame = CGRectMake(0, 0, 80, 44);
        [right setTitle:@"历史记录" forState:UIControlStateNormal];
        [right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        right.titleLabel.textAlignment = NSTextAlignmentRight;
        right.titleLabel.font = [UIFont systemFontOfSize:16];
        [right addTarget:self action:@selector(rightItemAction) forControlEvents:UIControlEventTouchUpInside];
        right.width = 80;
        [self.navigationItem setRightBarButtonItems:@[flexSpacer,[[UIBarButtonItem alloc] initWithCustomView:right]]];
    
    

    一开始宽度为35,在iOS11上是没问题的。

    相关文章

      网友评论

          本文标题:在苹果5s导航栏右边文字按钮显示“...”

          本文链接:https://www.haomeiwen.com/subject/ysoiuftx.html