[英]how to create Login screen (as a UIAlertView) in iphone?
如何在UIViewController中創建LoginScreen? 點擊按鈕后它應該看起來像UIAlertView。
從iOS5開始,UIAlertView現在支持使用Alert Style UIAlertViewStyleLoginAndPasswordInput
的登錄屏幕。
從iOS 5開始,您可以通過修改其alertViewStyle
屬性將文本字段或一對文本字段添加到UIAlertView
。
alertViewStyle
有四種不同的選項:
UIAlertViewStyleDefault = 0, // No text fields
UIAlertViewStyleSecureTextInput, // A single text field with secure input
UIAlertViewStylePlainTextInput, // A single text field with plaintext input
UIAlertViewStyleLoginAndPasswordInput // A pair of text fields, one with plaintext and one with a password
要訪問文本字段,請在UIAlertView
實例上調用textFieldAtIndex:
. 根據文檔,索引從0開始。
在iOS 5.0之前的遺留答案:
如果您希望使用文本框呈現UIAlertView,iOS中的任何公共API都不支持此功能,盡管您可以遍歷視圖層次結構並添加自己的文本框。
或者,創建一個新的UIViewController子類並以模態方式呈現它。 然后,您可以在視圖被關閉時檢查值。
看看這個鏈接 ,並在UIAlertView中添加用戶名和密碼字段。
您可以將UIAlertView子類化並向其添加UITextFields並定義指定的初始值設定項,如下所示:
- (id)initWithTitle:(NSString *)title message:(NSString *)message
delegate:(id)aDelegate
cancelButtonTitle:(NSString*)cancelButtonTitle otherButtonTitle:(NSString*)otherButtonTitle { }
在此方法內部初始化文本字段並將其作為subView
添加到視圖中( subView
UIAlertView)。
希望它能幫到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.