22
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UILabelのheightやwidthを文字列の長さに合わせて調整する

Posted at

こんな感じで書くといけます!

Labelに表示したい文字列をmyObjectに、boldSystemFontOfSizeにフォントサイズを、maxWidthに最大のwidthを入れてあげるとCGSizeが取得できます。

CGSize textSize = [[myObject getALongText] 
                    sizeWithFont:[UIFont boldSystemFontOfSize:15] 
                    constrainedToSize:CGSizeMake(maxWidth, 2000)
                    lineBreakMode:UILineBreakModeWordWrap];

詳しくはこちら。
http://stackoverflow.com/questions/5430890/uilabel-auto-resize-on-basis-of-text-to-be-shown

22
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?