如何仅在UIAlertView中对齐标题 [英] How to align only the title in UIAlertView
本文介绍了如何仅在UIAlertView中对齐标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想只将UIAlertView中的标题居中对齐,而消息则应左对齐.
I would like to align center only the title in UIAlertView, while the message should be align left.
我现在正在做
((UILabel*)[[alert subviews] objectAtIndex:1]).textAlignment = NSTextAlignmentCenter;
但是它也使消息居中对齐.
But it aligns center also the message.
推荐答案
我不会尝试修改UIAlertView的默认标签,而是应该创建一个新的UILabel并将其添加为子视图.
I wouldn't try to modify the default labels of the UIAlertView, instead you should create a new UILabel and add it as a subview.
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];
这篇关于如何仅在UIAlertView中对齐标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文