How to align messages in UIAlertView?

前端 未结 3 744
时光说笑
时光说笑 2021-02-04 16:16

i want to know how to set the alignment of delegate message of alert view. anyone has solution, plz reply with some code.

相关标签:
3条回答
  • 2021-02-04 16:43

    This is just a slightly simplified version of the previous answer but I like to keep things simple. :)

    for (UIView *view in alert.subviews) {
        if([[view class] isSubclassOfClass:[UILabel class]]) {
            ((UILabel*)view).textAlignment = NSTextAlignmentLeft;
        }
    }
    
    0 讨论(0)
  • 2021-02-04 16:43

    the code below is not work on iOS7, only before iOS7.

    for (UIView *view in alert.subviews) {
        if([[view class] isSubclassOfClass:[UILabel class]]) {
           ((UILabel*)view).textAlignment = NSTextAlignmentLeft;
        }
    }
    

    the question Align message in UIAlertView to left in iOS 7 solve this problem.

    0 讨论(0)
  • 2021-02-04 17:01

    You need to get alertView's subViews. Iterate through the array of subview's, it will be having one item of type UILable. Get that UILabel from subview array and for that you can set textAlignment property.

    NSArray *subViewArray = alertView.subviews;
     for(int x=0;x<[subViewArray count];x++){
     if([[[subViewArray objectAtIndex:x] class] isSubclassOfClass:[UILabel class]])
      {
          UILabel *label = [subViewArray objectAtIndex:x];
        label.textAlignment = UITextAlignmentCenter;
      }
    
    }
    
    0 讨论(0)
提交回复
热议问题