AppleWatch开发-AlertController
生活随笔
收集整理的這篇文章主要介紹了
AppleWatch开发-AlertController
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
AlertController
前言
AlertController控件效果
(1)Alert樣式
- (2)SideBySideButtonsAlert樣式
- (3)ActionSheet樣式
1.1-簡介
彈出一個AlertController控件是Watch OS2.0中新增的方法
AlertController類似于iPhone中的ActionSheet控件和AlertView控件
不同的是Alert與ActionSheet只是AlertController的一種style
- WatchOS2.0是把AlertView和ActionSheet集成到AlertController中
1.2-API
- 非常簡單的一個方法,直接集成在WKInterfaceController中
1.3-示例
/*創建按鈕點擊對應的action第一個參數:標題第二個參數:stylecase Deault 默認樣式case Cancel 在左上角顯示case Destructive 紅色顯示第三個參數:點擊回調*/let action1 = WKAlertAction(title: "按鈕1", style: WKAlertActionStyle.Cancel) { () -> Void inprint("點擊按鈕1")}let action2 = WKAlertAction(title: "按鈕2", style: WKAlertActionStyle.Destructive) { () -> Void inprint("點擊按鈕2")}let action3 = WKAlertAction(title: "按鈕3", style: WKAlertActionStyle.Default) { () -> Void inprint("點擊按鈕3")}/*第一個參數:標題第二個參數:信息第三個參數:stylecase Alert 備注:一定要一個或以上的action 否則報錯requires one or more actions case SideBySideButtonsAlert 備注:一定只能是兩個action 否則報錯exactly two actions are needed for WKAlertControllerStyleSideBySideButtonsAlertcase ActionSheet第四個參數:按鈕點擊對應的方法actions*/presentAlertControllerWithTitle("title", message: "message", preferredStyle: WKAlertControllerStyle.ActionSheet, actions: [action1,action2,action3])1.4-注意事項
Alert樣式和ActionSheet樣式的唯一區別是Alert樣式左上角沒有Cancel按鈕,而ActionSheet樣式左上角有Cancel按鈕用于取消選擇
Alert樣式不支持AlertAction的Cancel樣式,而ActionSheet樣式支持
總結
以上是生活随笔為你收集整理的AppleWatch开发-AlertController的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 01-iOS获取系统iTunes音乐
- 下一篇: ARKit从入门到精通(2)-ARKit