0

メッセージは左揃えにする必要がありますが、UIAlertView のタイトルのみを中央揃えにしたいと思います。

現在、私はやっています

((UILabel*)[[alert subviews] objectAtIndex:1]).textAlignment = NSTextAlignmentCenter;

しかし、メッセージも中央に配置されます。

4

1 に答える 1

1

UIAlertView のデフォルトのラベルを変更しようとはしません。代わりに、新しい UILabel を作成してサブビューとして追加する必要があります。

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Centered Title" message:@"\n\n\n" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12.0, 24.0, 250.0, 80.0)];
label.numberOfLines = 0;
label.textAlignment = NSTextAlignmentLeft;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.text = @"Here is an example of a left aligned label in a UIAlertView!";
[alert addSubview:label];
[alert show];

ここに画像の説明を入力

于 2013-04-03T14:47:20.027 に答える