[Objective-C] 関数リファレンス #UILabel

2015年10月1日

Objective-C テクノロジー プログラミング

文字を表示する枠に当たる部分。 HTMLで言うところのDIVやSPANのような役割り。 サイズ、色、形などを組み合わせて、表示を工夫することで、利用する割合の高い命令。 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UILabel *cell = [[UILabel alloc] init]; cell.frame = CGRectMake(100,100,100,100); cell.text = @"View-Test"; cell.layer.borderWidth = 2; cell.layer.borderColor = [[UIColor redColor] CGColor]; cell.textAlignment = NSTextAlignmentCenter; cell.numberOfLines = 3; cell.textColor = [UIColor redColor]; [self.view addSubview:cell]; }

プロパティ

標準

text UILabel内に記述する文字列 textAlignment 右 : UITextAlignmentRight 左 : UITextAlignmentLeft 中央 : UITextAlignmentCenter numberObLines 改行数を指定する。 0 : 無限 1 : 1行のみ表示(Default) 2 : 2行のみ表示(以上の数値で行数指定)

frame

frame オブジェクトのサイズ、位置などを指定。(CGRectMake)

layer

layer.borderWidth 枠線の幅 layer.orderColor 枠線の色

サンプル

# 位置[x,y]、サイズ[w,h] cell.frame = CGRectMake(50,50,100,150); # 枠線サイズ cell.layer.borderWidth = 2; # 枠線カラー cell.layer.borderColor = [[UIColor redColor] CGColor]; # 中央寄せ cell.textAlignment = NSTextAlignmentCenter; # 文字色 cell.textColor = [UIColor redColor]; # 角丸 cell.layer.cornerRadius = 10.0;

注意点

1、デフォルト状態で、枠内を文字列がはみ出す場合は、「ABCDEFG」という文字列の場合「ABC...」という風になる。 回避するには、「numberObLines」を使って改行する。 2、ボーダー色とテキスト色のcolor設定は若干違うのでサンプルを見て理解して、注意すること。

その他

調査段階ではiOS9のバージョンです。

このブログを検索

ごあいさつ

このWebサイトは、独自思考で我が道を行くユゲタの少し尖った思考のTechブログです。 毎日興味がどんどん切り替わるので、テーマはマルチになっています。 もしかしたらアイデアに困っている人の助けになるかもしれません。