티스토리 뷰

CGRect frame = _textView.frame;
frame
.size.height = _textView.contentSize.height;
_textView
.frame = frame;
Edit: sizeThatFits returns the size but does not actually resize the component. I'm not sure if that's what you want, or if [textView sizeToFit] is more what you were looking for. In either case, I do not know if it will perfectly fit the content like you want, but it's the first thing to try.

- http://stackoverflow.com/questions/50467/how-do-i-size-a-uitextview-to-its-content


ps > 테이블 생성시 높이 지정을 위해서 UITextView 생성을 하고 높이를 구하려 할때는 cellForRowAtIndexPath 에서 셀 생성 하듯이 하나 만들어서... (heightForRowAtIndexPath 에 임의로 실제 사용하는 셀을 생성해서 적용해보고 구해오기)
ps2 > sizeToFit 날리기 전에 사이즈 항상 늘려놓기(셀 재사용으로 인해 전에 설정이 이후에 영향을 미침)


위 방법은 테이블이 많이 길어지면 느려서..

CGSize maximumSize = CGSizeMake(300, 9999);
NSString *dateString = @"The date today is January 1st, 1999";
UIFont *dateFont = [UIFont fontWithName:@"Helvetica" size:14];
CGSize dateStringSize = [dateString sizeWithFont:dateFont
        constrainedToSize
:maximumSize
        lineBreakMode
:self.dateLabel.lineBreakMode];

CGRect dateFrame = CGRectMake(10, 10, 300, dateStringSize.height);

self
.dateLabel.frame = dateFrame;

이렇게도 가능




공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함