Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sizeToFit with maximum width

I am trying to programmatically manipulate a UILabel so that it has a dynamic width.

I found that using sizeToFit() does this exact behavior. Now as this label becomes my navigationItem.titleView. I want it to have a maximum size, which can't be extended.

It is important to fit 2 barButtonItems in the navigationItem. For instance: a backBarButton on the left, an addButton on the right.

Is there a way to change the sizeToFit() method?

like image 864
JVS Avatar asked May 17 '16 13:05

JVS


1 Answers

You can use sizeThatFits: see docs here.

You have to specify a CGSize that you want to fit in.

like image 127
Marius Fanu Avatar answered Oct 21 '22 05:10

Marius Fanu