sizetofit

iOS: UITextView set height equal to content height

我怕爱的太早我们不能终老 提交于 2019-12-04 02:21:52
问题 I have a UITextView with disabled scrolling and I need to set the height of the UITextView to match the height of the text content. I have tried various methods found the internet with no results. This is my code for the layout of the UITextView: -(void) viewDidLayoutSubviews { // UITextView is named jobDescrip jobDescrip.scrollEnabled = NO; [jobDescrip sizeToFit]; [jobDescrip layoutIfNeeded]; } I have also tried this code in the viewDidAppear: method. Can someone please post code for an iOS

How can I add padding to the intrinsic content size of UILabel?

邮差的信 提交于 2019-12-03 08:35:57
问题 I'm using autolayout on iOS7 and I have a problem like this: I'm putting a UILabel onto a UIView and I'm arranging my autolayout constraints so that the label's centerX = parent view's centerX. I'm not giving any width constraint to the label. When I set the label's text on runtime, the label is drawn just wide enough for the text to fit, there are no margins/paddings on the left and right sides. What I want is to have some padding on the left and right sides, so that the text doesn't begin

How can I add padding to the intrinsic content size of UILabel?

℡╲_俬逩灬. 提交于 2019-12-03 00:06:24
I'm using autolayout on iOS7 and I have a problem like this: I'm putting a UILabel onto a UIView and I'm arranging my autolayout constraints so that the label's centerX = parent view's centerX. I'm not giving any width constraint to the label. When I set the label's text on runtime, the label is drawn just wide enough for the text to fit, there are no margins/paddings on the left and right sides. What I want is to have some padding on the left and right sides, so that the text doesn't begin just where the label begins. The hack to achieve this could be setting the text as @" text " but of

iOS: UITextView set height equal to content height

安稳与你 提交于 2019-12-01 13:53:54
I have a UITextView with disabled scrolling and I need to set the height of the UITextView to match the height of the text content. I have tried various methods found the internet with no results. This is my code for the layout of the UITextView: -(void) viewDidLayoutSubviews { // UITextView is named jobDescrip jobDescrip.scrollEnabled = NO; [jobDescrip sizeToFit]; [jobDescrip layoutIfNeeded]; } I have also tried this code in the viewDidAppear: method. Can someone please post code for an iOS 7.0 and later solution to this problem using auto layout? Have you tried this? I added a button, with

UILabel sizeToFit method not working properly

六月ゝ 毕业季﹏ 提交于 2019-11-30 11:03:55
I'm trying to show a long chunk of text inside a UILabel in one line. The UILabel is a subview of UIScrollView so I can scroll and see the entire UILabel. My problem is that the sizeToFit method only partialy works. textLabel.attributedText = attributedString; textLabel.numberOfLines = 1; [textLabel sizeToFit]; textScrollView.contentSize = CGSizeMake(textLabel.frame.size.width, textLabel.frame.size.height); The UIScrollView content size gets big enough to show the entire UILable, but for a line like: so i'll try to share some of them here every once in a while." The UILabel shows: so i'll try

UILabel sizeToFit method not working properly

本小妞迷上赌 提交于 2019-11-29 16:29:05
问题 I'm trying to show a long chunk of text inside a UILabel in one line. The UILabel is a subview of UIScrollView so I can scroll and see the entire UILabel. My problem is that the sizeToFit method only partialy works. textLabel.attributedText = attributedString; textLabel.numberOfLines = 1; [textLabel sizeToFit]; textScrollView.contentSize = CGSizeMake(textLabel.frame.size.width, textLabel.frame.size.height); The UIScrollView content size gets big enough to show the entire UILable, but for a

Weird thing occurs when using sizetofit of a UITextView in IOS7

牧云@^-^@ 提交于 2019-11-29 11:53:10
问题 When I test my app on IOS7 simulator. Sometimes I found it is weird when I using sizeToFit of a UITextView . The frame after sizeToFit seems right but the text can only show partly just like the photo below. (The gray area represents the UITextView new frame after sizeToFit , the whole sentence should be "which sparked a tense relationship between the two.") The UITextView text is set via attributedText. It seems the problem occurs with some sentences only and is OK for most sentences. I met

Resize UItextview according to it's content in iOS7

自古美人都是妖i 提交于 2019-11-28 20:53:04
I'm trying to resize a text view according to content & also it's sibling and parent container. Below code is working fine in iOS 6 if (/* less than ios 7 */) { CGRect frame = _textView.frame; CGSize conSize = _textView.contentSize; CGFloat difference = conSize.height - frame.size.height; frame.size.height += difference; _textView.frame = frame; UIScrollView *parentView = (UIScrollView *)_textView.superview; // adjust views residing below this text view. // sibling view UIView *belowView = // access it somehow CGRect frame1 = belowView.frame; frame1.origin.y += difference; belowView.frame =

Resizing UITableView to fit content

北城余情 提交于 2019-11-26 12:05:12
I am creating an app which will have a question in a UILabel and a multiple choice answers displayed in UITableView , each row showing a multiple choice. Questions and answers will vary, so I need this UITableView to be dynamic in height. I would like to find a sizeToFit work around for the table. Where the table's frame is set to the height of all it's content. Can anyone advise on how I can achieve this? MiMo Actually I found the answer myself. I just create a new CGRect for the tableView.frame with the height of table.contentSize.height That sets the height of the UITableView to the height

Resizing UITableView to fit content

拟墨画扇 提交于 2019-11-26 02:28:26
问题 I am creating an app which will have a question in a UILabel and a multiple choice answers displayed in UITableView , each row showing a multiple choice. Questions and answers will vary, so I need this UITableView to be dynamic in height. I would like to find a sizeToFit work around for the table. Where the table\'s frame is set to the height of all it\'s content. Can anyone advise on how I can achieve this? 回答1: Actually I found the answer myself. I just create a new CGRect for the tableView