dreamzor
dreamzor

Reputation: 5925

Set default Fixed Space UIBarButtonItem width

Basically, the title says everything. I'm trying to do some customization and i need to use less-than-zero width to make buttons be closer to each other.

I've learned it from this answer.

I can do it by manually setting every fixed space width, but how can I do it via [appearance] or something to make it default?

Something like this:

// works for every button not only Fixed Space
[UIBarButtonItem appearance] setWidth:-10]; 

!!! OR !!!

How can i set less-than-zero width in XCode? I'm creating everything using Storyboard anyway, it says that's not a valid value to set.

Any help would be really great.

Upvotes: 1

Views: 1177

Answers (1)

Mundi
Mundi

Reputation: 80265

I normally solve this kind of problem by subclassing the container and overriding layoutSubviews or didLayoutSubviews. This gives you a lot of control of all kind of styling behavior. In this particular case you would determine the widths programmatically and adjust the frames accordingly.

Make your instance class a subclass of this subclass, and you will have the layout code neatly separated from your implementation.

Upvotes: 2

Related Questions