Tabs

iPhone&Androidのアプリ制作・デザイン

*

UILabelをコードで生成(Tips付)

      2014/11/02


Main Storyboard (IB)に用意されている Label を使わずにコードのみで生成する場合。

// UIラベルを作成(CGRectMakeで位置と領域も指定)
UILabel *score = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 200, 40)];
// 背景色は黒
score.backgroundColor = [UIColor blackColor];

// 現在の形状でマスクする(角丸を実現させるためのステップ)
score.layer.masksToBounds = YES;
// 丸くしたい半径の数値を指定
score.layer.cornerRadius = 10.0;

// フォント(boldsSystemFont)とフォントサイズ(30)
score.font = [UIFont boldSystemFontOfSize:30];
// 初期テキストを入力しておく
score.text = @”00000″;

// テキストの横寄せを設定(1で中央揃え)※0で左 2で右揃え
score.textAlignment = 1;

// テキストの色をオレンジカラーに設定
score.textColor = [UIColor orangeColor];

// ビューにラベルを表示
[self.view addSubview:score];


 - Begin

  関連記事

no image
BGM・SE 導入方法

音楽:導入方法 1… AVFoundationフレームワークを追加 2… hファ …

eyechatch_xcode_tips-300x300
SNS連携

Twitter・Facebookとの連携は #import <Social …

no image
UIView

タイトル画面の背景など、新たにビューを追加した場合 UIViewを生成し sel …

no image
アプリの名前をつける

iPhoneのホーム画面に表示される「アプリ名」の付け方 アプリ名の変更には上 …

eyechatch_xcode_tips-300x300
ボタンに画像(背景)を指定する

// ボタンのサイズを指定する UIButton *startBtn = [[U …

eyechatch_xcode_tips-300x300
Xcode6 GameCenter 実装

Xcode6(iOS7以上)でのGameCenter実装 検索であまり見つからな …

no image
UIImageView 画像の差し替え

[UIImageView alloc] 後の画像を変換する時は下記コードを参照し …

eyechatch_xcode_tips-300x300
.selected

インスタンス名.selected で BOOLを宣言せずにボタンのON/OFF状 …

eyechatch_xcode_tips-300x300
テキストの文字間を詰める

UILabelなどで文字間を詰める(カーニング)したい時がちょいちょいあると思い …

no image
乱数のこと

乱数(ランダムな数)を取り出す際 rand や arc4random を使用しま …