彈出框

UIAlertController 包含 ?UIAlertView 和 UIActionSheet

1.UIActionSheet

UIActionSheet*sheet = [[UIActionSheetalloc]initWithTitle:@"你要做啥"delegate:nilcancelButtonTitle:@"是"destructiveButtonTitle:@"不是" otherButtonTitles:@"關(guān)閉",nil];

[sheet showInView:self.view];

展示在底部

2.UIAlertView

UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"message:@"確定關(guān)閉么"delegate:nilcancelButtonTitle:@"是"otherButtonTitles:@"不是",nil];

alert.alertViewStyle=UIAlertViewStyleLoginAndPasswordInput;

[alert show];

展示在中間

2.UIAlertController

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"message:@"完成"preferredStyle:UIAlertControllerStyleAlert];

[selfpresentViewController:alertanimated:YEScompletion:nil]; ?

展示在中間

添加 關(guān)閉 或者 取消 的按鈕事件 通過(guò)(UIAlertAction)

[alert addAction[UIAlertAction actionWithTitle:@"確定"style:UIAlertActionStyleDestructive handler:^(UIAlertAction*action) {? NSLog(@"點(diǎn)擊了確定按鈕"); }]];

[alert addAction:[UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancel handler:^(UIAlertAction*action) { ?NSLog(@"點(diǎn)擊了取消按鈕"); ?}]];

添加文本框

[alert addTextFieldWithConfiguration Handler:^(UITextField*textField) { textField.textColor= [UIColor blueColor];

textField.text=@"";

[textField addTarget:selfaction:@selector(usernameDidChange:)forControlEvents:UIControlEventEditingChanged];

}];

延伸:模態(tài)視圖?

模態(tài)視圖:從屏幕下方滑出來(lái),完成的時(shí)候需要關(guān)閉這個(gè)模態(tài)視圖,如果不關(guān)閉,就不能做別的事情,必須有響應(yīng)處理的含義主視圖控制器---》模態(tài)視圖控制器。主視圖控制器與模態(tài)視圖控制器之間為父子關(guān)系。

UIViewController類中,主要有以下兩個(gè)方法:

presentViewController:animated:completion 呈現(xiàn)模態(tài)視圖

dismissViewControllerAnimated:completion 關(guān)閉模態(tài)視圖

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容