iOSアプリでラベルを試してみる

iOSアプリの開発を始めてみる
の続き

今回はラベルを試してみる。

ラベルの設置

Main.storyboardを選んで右下のオブジェクトのライブラリから ドラッグ&ドロップして設置する。

属性の変更

ラベルを選んだ後、属性のインスペクタで フォントや色などの各種属性を変更できる。

今回はテキストやフォントや背景色、ラベルのサイズを変更してみた。

確認

シミュレータで確認してみる。

Main.storyboardのファイルの中身を見てみると、 下記のような感じで、インスペクタで設定した値がXMLで設定されているのが確認できる。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document ・・・>
  ・・・
  <scenes>
    <!--View Controller-->
    <scene ・・・>
      <objects>
        <viewController ・・・>
          ・・・
          <view ・・・>
            ・・・
            <subviews>
              <label ・・・ text="ラベル" ・・・>
                <rect key="frame" x="147" y="169" width="120" height="60"/>
                <color key="backgroundColor" red="0.0" green="1" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
                <fontDescription key="fontDescription" style="UICTFontTextStyleTitle1"/>
                <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
                ・・・
              </label>
            </subviews>
            ・・・
          </view>
        </viewController>
        ・・・
      </objects>
      ・・・
    </scene>
  </scenes>
</document>