iPhone視圖控制項之--UIAlertView

來源:互聯網
上載者:User

警告提示視圖

NSString *content = NSLocalizedString(@"this is test alert message", nil);UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"alert title", nil)                                                    message:content                                                   delegate:self                                          cancelButtonTitle:NSLocalizedString(@"cancel", nil)                                          otherButtonTitles:NSLocalizedString(@"ok", nil), nil];    alert.tag = 1;  //用來作為標識,可區分不同的提示框    [alert show];

 

在使用的類裡,實現代理協議UIAlertViewDelegate

按鈕點擊處理方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {  switch(buttonIndex){    case 0:      //do cancel      break;    case 1:      //do ok      break;   }}

 

在UIAlertView顯示動畫之前,改變提示message的對其方式,改為靠左對齊

- (void)willPresentAlertView:(UIAlertView *)alertView{  //遍曆UIAlertView的子視圖,改變label的大小,尺寸,和對齊    for(UIView *subview in alertView.subviews)    {        if([[subview class] isSubclassOfClass:[UILabel class]])        {            if(![((UILabel *)subview).text isEqualToString:iGexinLocalizedString(@"file detail", nil)]){                                UILabel *label = (UILabel*)subview;                CGRect rect = CGRectInset(label.frame, 20, 0);  //label邊界留20                NSString * labelText = label.text;                CGFloat oldH = rect.size.height;                rect.size = [labelText sizeWithFont:label.font constrainedToSize:                                  CGSizeMake(rect.size.width, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap]; //計算文本的寬度和高度                if(oldH < rect.size.height){                    rect.origin.y -= 10;                }                label.frame = rect;                    //調整label的位置和尺寸                label.textAlignment = UITextAlignmentLeft;      //label文本靠左對齊                break;            }        }    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.