4

別のビューにセグエする一般的な丸みを帯びた四角形ボタンを持つビューがあります。ユーザーが丸みを帯びた四角形を押すと、フェッチが開始されます。フェッチの処理中に、丸みを帯びた四角形のボタン内のテキスト (「次へ」) を糸車で置き換えたいと思います。

スピナーを作成しました:

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[spinner startAnimating];

しかし、丸みを帯びた四角形のボタンのテキストを置き換える方法がわかりません。

なにか提案を?ありがとうございました。

4

2 に答える 2

7

通常どおりボタンを作成 (または参照を取得) し、ボタンのクリックを処理しながらスピナーを作成し、ボタンのサブビューとして設定します。ボタンを無効にして複数のクリックを停止することもおそらく価値があります。

次の行に沿った何かがうまくいくはずです:

  ...
  UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  button.frame = CGRectMake(10, 10, 70, 40);
  [button setTitle:@"Next" forState:UIControlStateNormal];
  [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:button];
  ...

- (void)click:(UIButton *)button {
  [button setTitle:@"" forState:UIControlStateNormal];
  UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  [spinner startAnimating];
  spinner.frame = button.bounds;
  [button addSubview:spinner];
  button.enabled = NO;

  // do your actual work...
}
于 2012-07-08T07:34:22.450 に答える