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
2
votes
2 answers

Label Size to Fit inside UITableView

The sizeToFit method of UILabel doesn't apply in cellForRowAtIndexPath. The problem is I need some of my cells to look like this: and others to look like this: What's the solution for this? Thanks
diogo.appDev
  • 1,605
  • 5
  • 16
  • 29
2
votes
1 answer

Shrink UIButton's frame after setting UIEdgeInsets

I hope, that it's quite simple question, but how I can fit UIButton's frame after following code (project without arc and *.nibs): _fotosButton = [UIButton buttonWithType: UIButtonTypeCustom]; [_fotosButton setImage: [UIImage imageNamed:…
Aliaksandr B.
  • 146
  • 16
2
votes
2 answers

UILabel dynamic width with sizeToFit on a cell

I have a custom UITableViewCell with a UILabel inside on the Storyboard. I set the text of this UILabel dynamically and I need to resize the width of the UILabel accordingly because after it I have another UILabel that must stay side to side. I am…
stilllife
  • 1,552
  • 1
  • 15
  • 34
2
votes
2 answers

Dynamic Height UILabel works after moving offscreen

I am trying to create multi-line dynamic UILabels in UITableViewCells. I have a custom UITableViewCell that has a 'comment' label. The cell and the label are created in storyboard. I can compute the heights of the UITableViewCells properly based…
user2312407
  • 57
  • 1
  • 11
2
votes
2 answers

Having difficulty wrapping text

I use the following code to add text in IOS //Set up label frame UILabel *tempLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 10, 210, 80)]; self.answer_text_label = tempLabel; [tempLabel release]; [self.preview_answer_container…
Zhen
  • 11,973
  • 37
  • 117
  • 194
1
vote
1 answer

What is the CALayer equivalent to UIView's sizeToFit-method?

I'm searching for a way to let a CALayer resize itself whenever its sublayers change (which means either when the bounds of any sublayer change or when the sublayer array itself changes). When i worked with views before, i managed that through…
bg890
  • 11
  • 4
1
vote
0 answers

SwiftUI text doesn't fit when have length property change

Increase or decrease Int with buttons. When going from positive numbers to negative numbers or when a facto 10 is added sizeToFit cannot handle. Solution (?) Looks like it is a discrepancy between Preview and Simulator/Device. Maybe I should file a…
YoYoHu
  • 92
  • 1
  • 11
1
vote
1 answer

The content of UILabel is being truncated after rotation in Swift 4

I am using AutoLayout. I have a view with %10 width and 200 fixed height. I placed a UILabel into that view with 0 margins. Then I am rotating the UILabel, changing the content and calling sizeToFit() function. At the load of the controller the…
ozbek
  • 71
  • 5
1
vote
1 answer

UiTableview doesn't update sizetofit in iOS 10 but working in iOS 11

I am creating a dynamic TableView and i set the cell with the rowheight of 44 in the storyboard. So the tableview's height will be based on the number of rows that my database returns according to the results. At the same time, i am connecting the…
Drew
  • 103
  • 9
1
vote
1 answer

Is there any accurate way of calculating size of UILabel without using sizeToFit?

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…
dickyj
  • 1,672
  • 1
  • 19
  • 35
1
vote
2 answers

Possible to dynamically build layout?

I have a view for a contact. Based on the contact info the user provides, I would like to either include labels if the information is available, or not take up space if the information is not available to avoid a bunch of fields like tel: email:…
user1904273
  • 4,058
  • 11
  • 37
  • 82
1
vote
1 answer

UItableviewcontroller SizeToFit not working on UILabel field

Hi I am using sizetofit on my UILabel field, it works fine when I load the tableview controller, but then starts cutting of letters and wrapping to another line when I scroll up and down. Here is the code I use in CellForRowAtIndexPath: -…
Kitcc
  • 648
  • 2
  • 8
  • 18
1
vote
4 answers

How to change each UITableViewCell height dynamically?

I'm working on application where i show user comment in UILable and UILable have sizetofit property. i want to change cell height according to UILable height. My Question is how i change cell height for example first cell height may be 50, second…
Rizwan Shah
  • 687
  • 6
  • 18
1
vote
0 answers

UILabel in UITableViewCell doesn't autoresize IOS 8. (autolayout)

I have a table view with a basic autolayout for cells.My issue is that cell is autoresizing based on subviews, but it doesn't autoresize based on UILabel text, cell just stays at minimum height regardless of label text.I am really desperate as I…
1
vote
2 answers

Smart caption by UILabel or UITextView

I would like to create a smart caption as SoundCloud app did. See the attachment below, These two captions: - •PAN• - Berlin, Germany are what I want create. These captions seem to be executed by sizeToFit or sizeThatFits. However, if using…
user1574429
  • 241
  • 1
  • 4
  • 13