change position of cancel button in UIAlertView?

前端 未结 2 1415
星月不相逢
星月不相逢 2021-02-20 01:01

I noticed that when I delete an app from my iPhone home screen, the alert view that appears shows a Delete button on the left and Cancel on the right. However, when I build a de

2条回答
  •  被撕碎了的回忆
    2021-02-20 01:29

    Ah, I just figured out how to change this. The cancelButtonTitle argument is optional, so you can add a custom button in whatever position you want and then designate that as the cancel button, like this:

    UIAlertView *alert = [[UIAlertView alloc] 
                          initWithTitle:@"Delete Song" 
                          message:@"Are you sure you want to delete this song? This will permanently remove it from your database." 
                          delegate:self 
                          cancelButtonTitle:nil
                          otherButtonTitles:@"Delete", @"Cancel", nil];
    alert.cancelButtonIndex = 1;
    

    That puts the Delete button the left and the Cancel button on the right and highlights the Cancel button.

提交回复
热议问题