UILabel

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
上寄せ
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
label.text = @"xxxxxxxxxx";
// 設定後、行う
CGRect rect = label.frame;
[label sizeToFit];
rect.size.height = CGRectGetHeight(label.frame);
label.frame = rect;

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
サンプル
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

UILabel textLabel = [[UILabel alloc] init];

textLabel.text = @"あいうえおかきくけこ";

//改行モード(ここでは単語がおさまらなかったら単語毎改行)
textLabel.lineBreakMode  = UILineBreakModeWordWrap;
//行数 行数制限なしにする
textLabel.numberOfLines  = 0;
//サイズ 幅が大事(幅を指定しなかったら改行コード\nでしか改行しない)高さは後で変わるので適当。x、yはご希望の位置に
textLabel.frame          = CGRectMake(0, 0, 320, 10);

//高さを自動で合わせる
[_notesLabel sizeToFit];


_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
改行モード(lineBreakMode)
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
label.lineBreakMode = NSLineBreakByCharWrapping;

typedef NS_ENUM(NSInteger, NSLineBreakMode) { /* What to do with long lines */
    NSLineBreakByWordWrapping = 0,     /* Wrap at word boundaries, default */
    NSLineBreakByCharWrapping, /* Wrap at character boundaries */
    NSLineBreakByClipping, /* Simply clip */
    NSLineBreakByTruncatingHead, /* Truncate at head of line: "...wxyz" */
    NSLineBreakByTruncatingTail, /* Truncate at tail of line: "abcd..." */
    NSLineBreakByTruncatingMiddle /* Truncate middle of line:  "ab...yz" */
} NS_ENUM_AVAILABLE_IOS(6_0);


備考)
    if (SYSTEM_VERSION_LESS_THAN(@"8.0.0")) {
        // iOS8未満のみ有効
        // 文字列が多い場合、iOS7では上にズレて表示される問題が生じる為。
        label.lineBreakMode = NSLineBreakByCharWrapping;
    }


_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
センタリング
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
label.textAlignment = NSTextAlignmentCenter;

/* Values for NSTextAlignment */
typedef NS_ENUM(NSInteger, NSTextAlignment) {
    NSTextAlignmentLeft      = 0,    // Visually left aligned
#if TARGET_OS_IPHONE
    NSTextAlignmentCenter    = 1,    // Visually centered
    NSTextAlignmentRight     = 2,    // Visually right aligned
#else /* !TARGET_OS_IPHONE */
    NSTextAlignmentRight     = 1,    // Visually right aligned
    NSTextAlignmentCenter    = 2,    // Visually centered
#endif
    NSTextAlignmentJustified = 3,    // Fully-justified. The last line in a paragraph is natural-aligned.
    NSTextAlignmentNatural   = 4,    // Indicates the default alignment for script
} NS_ENUM_AVAILABLE_IOS(6_0);


_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
複数行表示化
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
label.numberOfLines = 0;

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
複数行で表示する
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByCharWrapping;
label.adjustsFontSizeToFitWidth = YES;

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
フォントサイズ可変化
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
label.minimumScaleFactor = 9.f/14.f;
label.adjustsFontSizeToFitWidth = YES;
最終更新:2016年10月26日 17:33