Search code examples
iosuibarbuttonitemuibarbuttonsystemitem

How to test if item in toolBar is FlexibleSpace item?


I want to know which UIBarButtonItem enumerated in self.toolbarItems is a button and which is flexible space item.


Solution

  • As A-Live confirmed my findings that one is not able to query the UIBarButtonItem to check if it is FlexibleSpace (or FixedSpace) I've used tag to mark those items as flexible and fixed space (2 different integers) and put those numbers in the constant then in code I use:

    for(int i=0; i<self.toolbarItems.count; i++)
    {
        if(item.tag != TOOLBAR_FIXED_SPACE_TAG && 
           item.tag != TOOLBAR_FLEXIBLE_SPACE_TAG)
        {
            //count real button:)
        }
    }