TextAlign在UIAlertView中不起作用?

时间:2015-08-07 11:37:29

标签: ios objective-c iphone uialertview text-alignment

我想在UIAlertView中对齐我的消息文本,这是我的代码,但是当我运行此代码时,文本显示为以前,并且在循环之后没有任何变化。我还想增加我的文字?我现在正在使用此代码Here

UIAlertView *alret = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%@",[title objectAtIndex:indexPath.row]]
                message:[NSString stringWithFormat:@"%@",[description objectAtIndex:indexPath.row]]
                delegate:nil
                cancelButtonTitle:@"OK"
                otherButtonTitles:nil];
for(id subview in alret.subviews) {
    if([subview isKindOfClass:[UITextView class]]) {
        [(UITextView *)subview setTextAlignment:NSTextAlignmentJustified];       
    }
}
[alret show];

1 个答案:

答案 0 :(得分:0)

试试这个

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

希望它有所帮助。