AutoLayout constraints are a huge improvement for page layout, but it doesn't always act the way it should. Take the
UILabel for example. When constrained to another control, and the number of lines is set to
0, the text should be forced to wrap due to the
constraints. Unfortunately what you get looks like this. The constraint on the
UILabel is ignored.
Luckily there is a simple workaround, shown here in C# (for Xamarin.iOS).
internal class CustomUILabel : UILabel
#region Overrides of UIView
public override void LayoutSubviews ()
this.PreferredMaxLayoutWidth = this.Superview.Bounds.Size.Width;
UIView and overriding
LayoutSubviews, we can set
to the width of the control's parent, resulting the expected result:
Simply use the new class in place of
- December 9, 2013: Initial publication.
Yvan Rodrigues has 25 years of experience in information systems and software development for the manufacturing sector. He runs Red Cell Innovation Inc.
/L'innovation de Globules Rouges
, a consulting company focusing on efficiency and automation of manufacturing and business processes for small businesses, healthcare, and the public sector. He is a Certified Technician (C.Tech.), a professional designation granted by the Institute of Engineering Technology of Ontario (IETO).
Yvan draws on experience at Mabel's Labels Inc.
as Manager of Systems and Development, and the University of Waterloo
as Information Systems Manager.
Yvan supports open-source software. He is a committer for SharpKit
(Issue/Ticket Management System), and contributes to MySQL, Ghostscript, iTextSharp, Bacula, FreeBSD, MonoTouch, and Mono for Android.
Yvan's consumer-focused apps can be found in the Windows Store, Apple App Store, and Google Play marketplace.