Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set max width of a UIBarButtonItem

I have a UIBarButtonItem in a UIToolbar that is updated with changes to a title represented by a text field. The text field should not have a short maximum length. When the title is quite long, the item occludes the button items to its right. How can I make it automatically truncate to a certain width? Interface BuilderSimulator

like image 745
Peter DeWeese Avatar asked Jul 19 '11 15:07

Peter DeWeese


People also ask

How can I customize the appearance of buttons in uinavigationitem?

However, you can customize the appearance of buttons by sending the setter messages to UIBarButtonItemAppearance to customize all buttons, or to a specific UIBarButtonItem instance. You can use customized buttons in standard places in a UINavigationItem object ( backBarButtonItem, leftBarButtonItem, rightBarButtonItem) or a UIToolbar instance.

When should I use uibarmetrics default values?

Similarly, when a property is depends on the bar metrics (for instance, on the iPhone, in landscape orientation, bars have a different height from the standard), you should specify a value of UIBarMetrics.default. For more information about appearance and behavior configuration, see Toolbars.

Is it possible to set width at a column level for Mui?

Is it possible to set width at a column level for Material-UI tables? Essentially, the answer is “yes” because the TableCell components act as a proxy for the column. MUI Tables are constructed in a table -> row -> cell pattern and use children components instead of a column prop to scaffold the table. A brief example is below.

Why do we use max-width for scrollbars?

The browser then adds a horizontal scrollbar to the page. Using max-width instead, in this situation, will improve the browser's handling of small windows. This is important when making a site usable on small devices: This <div> element has a max-width of 500px, and margin set to auto.


1 Answers

Use a custom view with maximum possible width, textAlignment set to UITextAlignmentCenter and lineBreakMode to UILineBreakModeTailTruncation.

UILabel* l = [[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 20)]autorelease];
//200 is just a number I choose. you should calculate your maximum possible value
l.textAlignment = UITextAlignmentCenter;
l.lineBreakMode = UILineBreakModeTailTruncation;
self.navigationItem.titleView = l;
like image 113
Ariel Avatar answered Sep 28 '22 14:09

Ariel