iPhone视图控件之--UIAlertView

警告提示视图

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;
            }
        }
    }
}

转载于:https://www.cnblogs.com/xiaodao/archive/2012/07/12/2588582.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值