Questions tagged [sizetofit]

- sizeToFit Resizes and moves the receiver view so it just encloses its subviews.

Declaration in OBJECTIVE-C

- (void)sizeToFit

Declaration in SWIFT

func sizeToFit()

Discussion Call this method when you want to resize the current view so that it uses the most appropriate amount of space. Specific UIKit views resize themselves according to their own internal needs. In some cases, if a view does not have a superview, it may size itself to the screen bounds. Thus, if you want a given view to size itself to its parent view, you should add it to the parent view before calling this method.

You should not override this method. If you want to change the default sizing information for your view, override the sizeThatFits: instead. That method performs any needed calculations and returns them to this method, which then makes the change.

Availability Available in iOS 2.0 and later.

95 questions
4
votes
4 answers

uicollectionview's dynamic height as per row values

hello friends i am using collection view in iPhone application to show list. I want to set the height of the collection view as per size of my list. how can I set it? also have the problem when I use set selected method of cell in the collection…
Premal Khetani
  • 3,167
  • 1
  • 22
  • 56
4
votes
1 answer

iOS 7 UITextView height resize quirk

Using information I've gathered from multiple answers I found here on stackoverflow, I've been able to correctly size a UITextView's height using: [bookQuoteTxtView sizeToFit]; [bookQuoteTxtView layoutIfNeeded]; I'm doing this because the…
sirab333
  • 3,502
  • 8
  • 37
  • 54
4
votes
3 answers

Positioning a UILabel directly beneath another UILabel

I have an addition to NSString which automatically resizes a UILabel depending on the text that's being read into it (I have a simple app showing quotations, so some are a few words, some a couple sentences). Below that quote label, I also have an…
Luke
  • 8,709
  • 14
  • 74
  • 140
4
votes
3 answers

ios - SizeToFit on UIImageView not working

I have a UIImageView which loads in images from the documents directory on the ios file system . The problem is that when I call [imageView sizeToFit]; It does not work. I think it is because the image hasn't loaded fully at that point and so the…
Ashley Staggs
  • 1,495
  • 9
  • 23
  • 38
3
votes
2 answers

Visually centering a UILabel to it's superview when the actual center looks off

I have a container UIView, and a UILabel. The container view size is set, I then add text to the UILabel, call sizeToFit on the label, and add the label as a subview of the container view. I then use the following code to center the label inside the…
user3344977
  • 3,454
  • 4
  • 29
  • 82
3
votes
1 answer

Change the size of UILabel or the font to fit in Accented Character

I have a UILabel with Text inside it called : self.textLabel; Now, I noticed that whenever I added an accented letter like Ä Ö Ü, then I get an effect like : Notice how the top dots on the accented letters are cut off. I want to get the text to…
gran_profaci
  • 7,133
  • 12
  • 55
  • 94
2
votes
2 answers

UILabel sizeToFit - Adjust position on object below

I'm writing a screen that has multiple UILabel on it, each one below the other on the screen. One of the labels has multiple lines and I've use [myLabel sizeToFit] along with myLabel.numberOfLines = 0 to enable word wrapping and the label to stretch…
Brian Boyle
  • 2,579
  • 5
  • 25
  • 34
2
votes
0 answers

sizeToFit label voids align right / set minimum width of label

Here is my code I am using to make a label (which contains content of an unknown length) the correct height for the content. (lines is equal to 0) myLabel.text =[NSString stringWithFormat:@"%@", myLabelContent]; myLabel.frame =…
Deco
  • 93
  • 2
  • 12
2
votes
1 answer

Can't resize a 100% width image down when the browser gets smaller

tl;dr: When an image takes up 100% width and height and the user resizes their browser down, the width and the height of the document don't change because the image keeps it from shrinking. I have a dynamically drawn SVG image (created by…
Tom Sykes
  • 135
  • 4
2
votes
1 answer

UITextView, sizeToFit doesnt work

I have a uitextview, I would like to dynamically load it based on the contents, the answer from this link doesnt work on iOS11. https://stackoverflow.com/a/20999067/365384 CGFloat fixedWidth = textView.frame.size.width; CGSize newSize =…
bitma
  • 97
  • 1
  • 14
2
votes
1 answer

Randomly placed UILabel has wrong size after rotation

Have a UIVew container for multiple UILabels random generated, rotated and placed into this view, also if I am using angles 0, 90, 180, 270 looks good but if angle randomly generated labels looks expanded, and this is problem for me because words…
Eugene
  • 145
  • 1
  • 10
2
votes
1 answer

How to determine the number of lines being used in UILabel (Swift)?

cell.bodyText.numberOfLines = 0 cell.bodyText.text = newsBody cell.bodyText.sizeToFit() I set the number of lines to 0 because the number of lines can vary (I am retrieving news articles and since every news article is obviously different in…
Schuey999
  • 3,868
  • 5
  • 18
  • 35
2
votes
1 answer

sizeThatFits sometimes returns a height that is one line more (or less) than my text in iOS 8

I try to get the fitting height for a UITextView with this code: [textView sizeThatFits:CGSizeMake(textView.frame.size.width, FLT_MAX)].height; It returns the correct value most of the time, but sometimes it returns a value that is one line more or…
Tamás Sengel
  • 47,657
  • 24
  • 144
  • 178
2
votes
2 answers

AdjustsFontSizeToFitWidth vs. SizeToFit

I'm using SizeToFit because I don't have to specify the Frame property to have an adaptive size of the UIButton/UILabel. In my case it's a button on a toolbar. Now I made the following observation: If I use AdjustsFontSizeToFitWidth together with…
testing
  • 17,950
  • 38
  • 208
  • 373
2
votes
2 answers

Dynamic view changes (i.e. UILabel) with autoLayout

I need to create two UILabels which should be resized dynamically based on text size inside UITableViewCell. The first UILabel should grow (based on the text) to the left and always align 15 points to the right border. the second UILabel should…
Asaf
  • 81
  • 8