0

我想仅在 UIAlertView 中将标题居中对齐,而消息应该左对齐。

目前我正在做

((UILabel*)[[alert subviews] objectAtIndex:1]).textAlignment = NSTextAlignmentCenter;

但它也使信息中心对齐。

4

1 回答 1

1

我不会尝试修改 UIAlertView 的默认标签,而是应该创建一个新的 UILabel 并将其添加为子视图。

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Centered Title" message:@"\n\n\n" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12.0, 24.0, 250.0, 80.0)];
label.numberOfLines = 0;
label.textAlignment = NSTextAlignmentLeft;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.text = @"Here is an example of a left aligned label in a UIAlertView!";
[alert addSubview:label];
[alert show];

在此处输入图像描述

于 2013-04-03T14:47:20.027 回答