xcode 如何在 UIAlertView 中对齐消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1392354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to align messages in UIAlertView?
提问by Swindler
i want to know how to set the alignment of delegate message of alert view. anyone has solution, plz reply with some code.
我想知道如何设置警报视图的委托消息的对齐方式。任何人都有解决方案,请回复一些代码。
回答by
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.
您需要获取alertView 的子视图。遍历子视图的数组,它将具有 UILable 类型的一项。从子视图数组中获取 UILabel,为此您可以设置 textAlignment 属性。
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;
}
}
回答by Swindler
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;
}
}
回答by riven
the code below is not work on iOS7, only before iOS7.
下面的代码不适用于 iOS7,仅在 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 7solve this problem.
问题在UIAlertView中对齐消息在IOS 7向左解决这个问题。