How to create fixed space and flexible space bar button items programmatically?

Linux world picture Linux world · Sep 7, 2010 · Viewed 73.4k times · Source

I want to create UIBarButtonItems programmatically and place these fixed space items between buttons.

Answer

Jerry Jones picture Jerry Jones · Sep 8, 2010
UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedItem.width = 20.0f; // or whatever you want

UIBarButtonItem *flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];