UIBarButton Item on screen edge in iOS 8 when used in standalone view

后端 未结 3 423
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 13:13

In my UINavigation bar added to a XIB with a number of UIViews the positioning of the left and right bar button item is way off:

3条回答
  •  情书的邮戳
    2021-01-17 14:04

    Not sure whats happening with UIBarButtonItem. It should be arrange by auto layout and it has to be work well. May be one of the constraint conflict with other or misguided.

    If you are not able to resolve it. I have one more solution for you. You need to create UIBarButtonItem programatically in your VC.

    The idea is to assign space from left and right padding before you add UIBarButtonItem.

    Below code will guide you to do the trick.

    UIBarButtonItem *leftPadding = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
                                    UIBarButtonSystemItemFixedSpace target:self action:nil];
    [leftPadding setWidth:5];  // Adjust width for padding from left side.
    
    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
                                  UIBarButtonSystemItemAdd target:self action:@selector(addButtonTapped:)];
    [self.navigationItem setLeftBarButtonItems:@[leftPadding, addButton]];
    
    
    UIBarButtonItem *rightPadding = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
                                     UIBarButtonSystemItemFixedSpace target:self action:nil];
    [rightPadding setWidth:10]; // Adjust width for padding from right side.
    
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
                                   UIBarButtonSystemItemDone target:self action:@selector(doneButtonTapped:)];
    
    [self.navigationItem setRightBarButtonItems:@[rightPadding, doneButton]];
    

提交回复
热议问题