Harita
Harita

Reputation:

How to align messages in UIAlertView?

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

Upvotes: 8

Views: 10683

Answers (3)

riven
riven

Reputation: 1516

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.

Upvotes: 1

shilpa
shilpa

Reputation:

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

}

Upvotes: 9

Swindler
Swindler

Reputation: 810

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

Upvotes: 9

Related Questions