How to adjust UIToolBar left and right padding

后端 未结 10 530
自闭症患者
自闭症患者 2020-12-02 05:05

I create one UIToolbar with code and another with interface builder. But, found out the two toolbar having different left and right padding which shown below:

From I

10条回答
  •  自闭症患者
    2020-12-02 05:38

    I stumbled upon this when trying to center a toolbar as a subview of an UIButton. As the toolbar needed to be of small width, the best solution was a flexible button on each side:

    UIBarButtonItem flexibleButtonItemLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    
    UIBarButtonItem centeredButtonItem = ...
    
    UIBarButtonItem flexibleButtonItemRight = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    
    UIToolbar toolbar = ...
    
    toolbar.items = @[flexibleButtonItemLeft, centeredButtonItem, flexibleButtonItemRight];
    

提交回复
热议问题