2013年8月11日日曜日

UITextFieldをコードで作成する

// UITextFieldの作成
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 250, 30)];
// UITextFieldのテキスト
//textField.text = @"My Name";
// プレースホルダー
textField.placeholder = @"Input your name";
// アライメント(デフォルト:NSTextAlignmentLeft)
// NSTextAlignmentLeft:左寄せ, NSTextAlignmentCenter:中央, NSTextAlignmentRight:右寄せ
textField.textAlignment = NSTextAlignmentLeft;
// フォント
textField.font = [UIFont systemFontOfSize:14];
// テキストの色(デフォルト:blackColor)
textField.textColor = [UIColor blackColor];
// 背景画像
//textField.background = [UIImage imageNamed:@"DialogInput.png"];
// 枠(デフォルト:UITextBorderStyleNone)
// 枠なし:UITextBorderStyleNone, Rect表示:UITextBorderStyleLine, UITextBorderStyleBezel,
// 角丸:UITextBorderStyleRoundedRect
textField.borderStyle = UITextBorderStyleRoundedRect;

[self.view addSubview:textField];

0 件のコメント:

コメントを投稿