日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

简述UIAlertView的属性和用法

發布時間:2023/12/29 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 简述UIAlertView的属性和用法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.Title

獲取或設置UIAlertView上的標題。

2.Message

獲取或設置UIAlertView上的消息

??? UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];

??? alertView.title = @"T";

??? alertView.message = @"M";

?

??? [alertView show];

?

3.numberOfButtons (只讀)

返回UIAlertView上有多少按鈕.

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];

??? NSLog(@"%d",alertView.numberOfButtons);

[alertView show];

?

?

4.cancelButtonIndex

?? UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示"?message:@"請選擇一個按 鈕:"?delegate:nil?cancelButtonTitle:@"取消"?otherButtonTitles:@"按鈕一", @"按鈕二", @"按鈕三",nil];

?? [alert show];

NSLog(@"UIAlertView中取消按鈕的角標是%d",alert.cancelButtonIndex);

效果:

?

注意不要認為取消按鈕的角標是4,“取消”,“按鈕一”,“按鈕二”,“按鈕三”的索引buttonIndex分別是0,1,2,3

?

?

5. alertViewStyle

5.1 UIAlertViewStyleLoginAndPasswordInput

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"產品信息展示" message:p.name delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];

???

alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;

???

// 彈出UIAlertView

?[alert show];

?

?

?

5.2 UIAlertViewStylePlainTextInput

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"產品信息展示" message:p.name delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];

???

alert.alertViewStyle = UIAlertViewStylePlainTextInput;

???

// 彈出UIAlertView

?[alert show];

?

?

5.3 UIAlertViewStyleSecureTextInput

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"產品信息展示" message:p.name delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];

???

alert.alertViewStyle = UIAlertViewStyleSecureTextInput;

???

// 彈出UIAlertView

?[alert show];


6. - (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex

返回textFieldIndex角標對應的文本框。

取出文本框文字

7.手動的取消對話框

[alert dismissWithClickedButtonIndex:0?animated:YES];

?

8. delegate

作為UIAlertView的代理,必須遵守UIAlertViewDelegate。

1.當點擊UIAlertView上的按鈕時,就會調用,并且當方法調完后,UIAlertView會自動消失。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

?

2.當UIAlertView即將出現的時候調用

- (void)willPresentAlertView:(UIAlertView *)alertView;

3. 當UIAlertView完全出現的時候調用

- (void)didPresentAlertView:(UIAlertView *)alertView;?

?

4. 當UIAlertView即將消失的時候調用

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex;

5. 當UIAlertView完全消失的時候調用

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;?

?

9.注意UIAlertView調用show顯示出來的時候,系統會自動強引用它,不會被釋放。

10. 為UIAlertView添加子視圖

在為UIAlertView對象太添加子視圖的過程中,有點是需要注意的地方,如果刪除按鈕,也就是取消UIAlerView視圖中所有的按鈕的時 候,可能會導致整個顯示結構失衡。按鈕占用的空間不會消失,我們也可以理解為這些按鈕沒有真正的刪除,僅僅是他不可見了而已。如果在 UIAlertview對象中僅僅用來顯示文本,那么,可以在消息的開頭添加換行符(@"\n)有助于平衡按鈕底部和頂部的空間。

下面的代碼用來演示如何為UIAlertview對象添加子視圖的方法。

UIAlertView*alert = [[UIAlertView?alloc]initWithTitle:@"請等待"?message:nil?delegate:nil ?cancelButtonTitle:nil?otherButtonTitles:nil]; ?

[alert?show];

UIActivityIndicatorView*activeView = [[UIActivityIndicatorView?alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

activeView.center?=?CGPointMake(alert.bounds.size.width / 2.0f, alert.bounds.size.height - 40.0f); ?

[activeView?startAnimating]; ?

[alert?addSubview:activeView]; ?

?

?11. UIAlertView小例子

??UIAlertView默認情況下所有的text是居中對齊的。 那如果需要將文本向左對齊或者添加其他控件比如輸入框時該怎么辦呢? 不用擔心, iPhone SDK還是很靈活的, 有很多delegate消息供調用程序使用。 所要做的就是在

- (void)willPresentAlertView:(UIAlertView *)alertView

中按照自己的需要修改或添加即可, 比如需要將消息文本左對齊,下面的代碼即可實現:

-(void) willPresentAlertView:(UIAlertView?*)alertView

{

??????for(?UIView?*?view?in?alertView.subviews?)

??????{

????????????if( [view?isKindOfClass:[UILabel?class]] )

????????????{

??????????????????UILabel* label = (UILabel*) view;

??????????????????label.textAlignment=UITextAlignmentLeft;

????????????}

??????}

}

?

轉載于:https://www.cnblogs.com/feife/p/4630323.html

總結

以上是生活随笔為你收集整理的简述UIAlertView的属性和用法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。