LoginSignup
6
5

More than 5 years have passed since last update.

読み込み時のLoadingViewのシンプルな実装

Last updated at Posted at 2013-09-20

シンプルな読み込み用View

読み込み中は、ユーザーにそのことを伝えておくとストレスが軽減されるため、多くのアプリでカスタマイズされたLoadingViewを表示しています。
標準的でシンプルなLoadingViewは以下の手順で簡単に実装できます。

また、非常に単純な実装にしてあるので、自分でいじってさらにリッチにカスタマイズすることも可能です。

サンプルプロジェクトはこちらからダウンロードしてください。

必要なファイル

  • LoadingView.h
  • LoadingView.m

LoadigViewの初期化

インスタンス変数を定義

ViewController.m
@interface ViewController ()
{   
    LoadingView *loadingView;           // 標準
    LoadingView *loadingViewWithTitle;  // カスタム
}
@end

初期化(標準とカスタムの2つ)

ViewController.m
// デフォルトテキストで初期化
loadingView = [[LoadingView alloc] init];
loadingView.center = CGPointMake(self.view.center.x, self.view.center.y-40);
[self.view addSubview:loadingView];

// カスタムテキストで初期化
loadingViewWithTitle = [[LoadingView alloc] initWithTitle:@"処理中..."];
loadingViewWithTitle.center = CGPointMake(self.view.center.x, self.view.center.y-40);
[self.view addSubview:loadingViewWithTitle];
// 色をカスタム
loadingViewWithTitle.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.7];

表示・非表示の切り替え

ViewController.m
// 表示
[loadingView show];
// 非表示
[loadingView hide];

※ 表示・非表示時には拡大縮小のアニメーションにより、ユーザーにとって何をしているかわかりやすいUXになっています。

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5