I know this question is a long shot, but I am just wondering if someone found a better solution. Using boundingRect is not accurate as it does not work with word wrapping. The reason I do not wish to use sizeToFit is that it incurs quite a hefty performance penalty when there are a lot of labels to calculate, thus causing jerkiness during scrolling (I am using UICollectionView).
Is there any accurate way of calculating size of UILabel without using sizeToFit?
202 views Asked by dickyj At
1
There are 1 answers
Related Questions in SWIFT
- Navigate after logged in with webservice
- URLSession requesting JSON array from server not working
- When using onDrag in SwiftUI on Mac how can I detect when the dragged object has been released anywhere?
- Protect OpenAI key using Firebase function
- How to correct error: "Cannot convert value of type 'MyType.Type' to expected argument type 'Binding<MyType>'"?
- How to share metadata of an audio url file to a WhatsApp conversation with friends
- Using @Bindable with a Observable type in SwiftUI
- How to make a scroll view of 9 images in a forEach loop open on image 6 if image 6 is clicked on from a grid?
- Using MTLPixelFormat.rgba16Float results in random round-off errors
- Search and highlight text of current text in PDFKit Swift
- How is passing a function as a parameter related to escaping autoclosure?
- Actionable notification api call not working in background
- Custom layout occupies all horizontal space
- Is it possible to fix slow CKAsset loading on Cloudkit?
- Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value - MapView.isMyLocationEnabled
Related Questions in UICOLLECTIONVIEW
- Strange CollectionView diffable data source crash on ios 17
- How to use RxSwift to draw the UICollectionView cells according to the number of data
- UIStepper disclosure indicator
- ColletionView inside table view not displaying data correctly
- UICollectionView scrollToItem not working when multiple cell visible on screen and cell size small iOS
- Using UICollectionViewCell with IBOutlet
- When using an UICollectionViewCompositionalLayout, is there a way to have a custom size for only certain items in the datasource?
- How to create the following design using Swift UIKit?
- How can I create horizontal collection view with auto height in swift?
- UICollectionViewCell auto or dynamic height
- When do we need to use 'leastNormalMagnitude', 'leastNonzeroMagnitude'?
- Waterfall UICollectionViewFlowLayout with expanding cell
- Animation in UICollectionViewCell Stops When Reloading Array Data
- How to set correct tintColor with selected but not focused UICellAccessory.customView
- UICollection view is not rendering properly
Related Questions in UILABEL
- How to UILabel Linebreak set character wrap + truncate tail?
- How I make "...more" feature like instagram by using UILabel
- Arabic Diacritics (Harakat) Misaligned in UILabel with Justified Text Alignment
- HTML tags in UILabel don't work and instead got shown
- UILabel with large font size causing huge memory usage
- UILabel not drawing text properly in UICollectionViewCell
- Dynamic Resizing of UILabel Based on Text Content
- Content hugging and content compression resistance with minimum margin between views
- UITextView causes abnormal number of gesture recognizer dependencies
- how to have "hour", "minute", "second" text behind UIPickView
- Why UILabel giving extra padding in swift?
- Allow label to use preferred width necessary to not character wrap (when word wrap is enabled)
- How can I get the x, y, width and height parameters of the text inside the UILabel?
- How to rotate the contents in a label?
- Swift UI center text below label and icon
Related Questions in SIZETOFIT
- Expanding UITextView with UIButton instead of automatically based on content
- UILabel and UIButton sizeToFit height are different in Swift
- SwiftUI text doesn't fit when have length property change
- how to fix width in UIButton's sizeToFit/sizeThatFit?
- SizeToFit() doesn't work properly with \n?
- UILabel SizetoFit After Specifying Number of Lines?
- iOS UITextView sizeToFit make height doubled of content text in iPad
- UILabel sizeToFit crashed when OS version is 11.2 and device's language is Japanese
- How to programmatically sizeToFit width AND height on UILabel?
- The content of UILabel is being truncated after rotation in Swift 4
- UITextView, sizeToFit doesnt work
- Adjusting the width of a UIButton depending on its title
- UiTableview doesn't update sizetofit in iOS 10 but working in iOS 11
- Is there any accurate way of calculating size of UILabel without using sizeToFit?
- sizeToFit not working like we expecting
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
There is the internal method that makes
sizeToFitpossible -sizeThatFits(_ size: CGSize) -> CGSize. You can use it to compute the size without actually relayouting the view.Except that there's nothing more. There's a lot of methods, as you mentioned that compute bounding boxes of strings with different fonts/attributes/whatever, but they are always a little off, as the UI controls have inner layout or margins that are not publicly accessible. Even if you get it to work now it changes heavily from iOS to iOS.
As a solution I propose caching the sizes. Invalidate on model changes, rotations or collection view width changes.