2016-10-07 18 views
0

我需要在UIAlertController的主體中添加一些額外的UI組件,以創建如下設計的警報。如何在iOS 9-10的UIAlertController正文中添加我的自定義UI組件?

AlertController with Custom Body

我沒有找到任何Apples's Documentation公共API。任何人都可以幫助我如何添加額外的標籤和複選框在警報機構?

+0

嘗試此鏈接http://stackoverflow.com/questions/22727842/how-to-add-checkbox-into-uialertview。如果您可以使用TPL,那麼github上有很多庫可以提供該選項 –

+0

使其成爲您自己的視圖並添加所有您想添加的UIComponents,並在需要時隱藏此視圖然後取消隱藏該視圖 –

回答

2

debug view花一小時後,我終於可以通過下面的代碼

let watingListAlert = UIAlertController(title: "Lista De espera", 
             message: "Algunos días seleccionados, no poseen disponibilidad en el chárter. Puede inscribirse a la lista de espera y el sistema lo tendrá en cuenta cuando algún espacio se libere\n\n\n", 
             preferredStyle: .alert) 


if let alertContentView = watingListAlert.view.subviews[0].subviews.last?.subviews.first?.subviews.first?.subviews[0] { 

    // alertContentView is the view where title and message labels are drawn 
    // Create your own UI Native components and add them on this view 
} 

提取的UIAlertControllerbody我終於能夠添加extra labelcheck boxUIAlertController的身體。你可以在GitHub看到我的完整項目。我創造了最終結果的gif。

Demonstration

+1

你是否爲標籤和複選框設置或指定了額外的空間,使其出現在UIAlertController的消息文本下方和兩個操作按鈕之上? –

+0

@PatNeedham您是否找到解決方案?這正是我的問題。我的自定義內容在動作按鈕上 –

相關問題