How to resize UILabels to fit content?
My program currently has thirty UILabels that may contain numbers between one and three digits. I want my UILabels to expand and shrink horizontally as the numbers within them change size. At the moment the text is shrinking and the UILabels size remains the same.
If this can be done just using the xib file this would be preferable to doing so programmatically but if this isn’t possible either would be great.
- iOS CAKeyframeAnimation rotationMode on UIImageView
- performSelector may cause a leak because its selector is unknown
- xCode: Library not found - lPods-Bolts - Exit Code 1
- Storyboard Could not instantiate class named UIStoryboardUnwindSegueTemplate crash
- Clean way to force view to load subviews early
- UITableView Using Swift
Solutions Collect From Internet About “How to resize UILabels to fit content?”
After setting the text of the label, call
sizeToFit on the label. This will make the label just big enough for the text.
BTW – why do you need to do this? Why not just make the labels big enough for the possible values and leave them that size? What benefit do you think you will get by shrinking the labels?
- cURL with Alamofire – Swift – multipart/form-data
- Objective-C setting NSDate to current UTC
- How to disable a button even when it is not running in the background in swift?
- Swift: Errors when using different integer sizes
- Vertical Fold Animation
- How to find file UTI for file, withouth pathExtension, in a path in Swift
- When to use a UIView vs. a UIViewController on the iPhone?
- Core Data predicate : unimplemented SQL generation for predicate
- .xcconfig? How to set environment variables
- How to extract the image source from an rss string
- Create NSDate from Unix timestamp
- iOS Swift: Resize image to 200x200pt/px
- Storing UIColor object in Core Data
- XCode: Can I delete test target?
- background image also scroll while scroll content in UISCROLLVIEW