Can I center a UIToolbar item?

后端 未结 4 1371
遥遥无期
遥遥无期 2021-02-13 21:57

I am putting a label on a UIToolbar (per this tip: Adding a UILabel to a UIToolbar).

But the toolbar has a button on the left side, and so flexible spaces throw the labe

4条回答
  •  余生分开走
    2021-02-13 22:34

    Add a flexible space item to the left and right of your center item, like you did. Then add a fixed space item at the end and set the width to whatever the left button width is -- somewhere around 28 pixels.

    UIBarButtonItem *fixedItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:NULL] autorelease];
    fixedItem.width = 28;
    

提交回复
热议问题