UIAlertViewをカスタマイズするには
UIAlertViewのカスタマイズにつまずいたのでメモ。
通常UIAlertViewを表示したい場合、以下のようなコードを作成する...と思う。
サイズを変更したかったので、showメソッドの前でframeを変更する。
が、考慮されない模様。
どうやら[alert show]した後でないとカスタマイズできない。
なので、以下のようにUIAlertViewDelegateの- (void)willPresentAlertView:(UIAlertView *)alertViewの中でalertViewのサイズを変更する。
当然ながらサイズを変更するとボタンの位置も変更したくなるので、以下のコードで無理やり変更。
ここでUIAlertViewのボタンはUIButtonではないので注意!!
てか、UIThreePartButtonって何?w
通常UIAlertViewを表示したい場合、以下のようなコードを作成する...と思う。
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"タイトル"
message:@"メッセージ"
delegate:self
cancelButtonTitle:@"キャンセル"
otherButtonTitles:@"決定", nil] autorelease];
[alert show];
サイズを変更したかったので、showメソッドの前でframeを変更する。
が、考慮されない模様。
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"タイトル"
message:@"メッセージ"
delegate:self
cancelButtonTitle:@"キャンセル"
otherButtonTitles:@"決定", nil] autorelease];
alert.frame = CGRectMake(0,0,150,150);//サイズ変更が考慮されない
[alert show];
どうやら[alert show]した後でないとカスタマイズできない。
なので、以下のようにUIAlertViewDelegateの- (void)willPresentAlertView:(UIAlertView *)alertViewの中でalertViewのサイズを変更する。
-(void)willPresentAlertView:(UIAlertView *)alertView{
CGRect alertFrame = CGRectMake(0,0,320,360);
alertView.frame = alertFrame;
}
当然ながらサイズを変更するとボタンの位置も変更したくなるので、以下のコードで無理やり変更。
ここでUIAlertViewのボタンはUIButtonではないので注意!!
for (UIView* view in alertView.subviews) {
if ([view isKindOfClass:NSClassFromString(@"UIThreePartButton")])
view.frame = CGRectMake(x,y,width,height);
}
てか、UIThreePartButtonって何?w

コメント
コメントを投稿