2013年8月3日土曜日

UILabelをコードで作成する

// ラベルの作成
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(20,32,120,21)];
// ラベルのテキスト
label.text = @"タイトル:";
// アライメント
// NSTextAlignmentLeft:左寄せ, NSTextAlignmentCenter:中央, NSTextAlignmentRight:右寄せ
label.textAlignment = NSTextAlignmentRight;
// フォント
label.font = [UIFont systemFontOfSize:16];
// ボールドフォント
//label.font = [UIFont boldSystemFontOfSize:14];
// 背景色
label.backgroundColor = [UIColor grayColor];
// テキストの色(デフォルト:blackColor)
label.textColor = [UIColor whiteColor];
// 影の色(デフォルト:nil)
label.shadowColor = [UIColor lightGrayColor];
// 影のオフセット(デフォルト:(0, -1))
label.shadowOffset = CGSizeMake(1, 1);
// 最大行数(デフォルト:1)
//label.numberOfLines = 1;
// ラベルをviewに追加
[self.view addSubview:label];

0 件のコメント:

コメントを投稿