根据主题,我的代码如下
- (void)viewDidLoad
{
// Add Scroll View
CGRect fullScreenRect = [[UIScreen mainScreen] applicationFrame];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:fullScreenRect];
self.view = scrollView;
// Configure Scroll View
scrollView.contentSize = CGSizeMake(320, 500);
// Shop Detail
CGRect shopDetailFrame = CGRectMake(20, 5, 300, 80);
UITextView *shopDetail = [[[UILabel alloc] initWithFrame:shopDetailFrame] autorelease];
shopDetail.backgroundColor = [UIColor whiteColor];
shopDetail.font = [UIFont boldSystemFontOfSize:15];
NSString *shopName = @"Shop A, G/F, 1/F-3/F, Lok Sing Building, 16 Kau Yuk Road";
shopDetail.text = [[shopName stringByAppendingString:@"\n"] stringByAppendingString:shopName];
[scrollView addSubview:shopDetail];
[super viewDidLoad];
}假设输出为:
Shop A, G/F, 1/F-3/F, Lok Sing Building, 16 Kau Yuk Road
Shop A, G/F, 1/F-3/F, Lok Sing Building, 16 Kau Yuk Road但是我得到了:
Shop A, G/F, 1/F-3/F, Lok Sing Building, 16 Kau Yuk Road...\n不能在UITextView上工作,有人知道如何在UITextView上换行吗?
谢谢
发布于 2011-12-09 16:47:18
就是这一行:
UITextView *shopDetail = [[[UILabel alloc] initWithFrame:shopDetailFrame] autorelease];您创建的是UILabel而不是UITextView。
您仍然可以使用UILabel,但默认情况下它将只显示一行。要使UILabel显示更多行,需要将numberOfLines属性设置为0 (无限制)或实际需要的行数。
发布于 2015-10-30 01:10:43
如果您以编程方式使用\n,它将正常工作。
var txt_Other_Proj = String()
txt_Other_Proj = "Other Jessit Apps and Projects"
txt_Other_Proj = txt_Other_Proj + "\n"
txt_Other_Proj = txt_Other_Proj + "Hurkle: A FIND ME game"
txt_Other_Proj = txt_Other_Proj + "\n"
txt_Other_Proj = txt_Other_Proj + "A free game."
txt_Other_Proj = txt_Other_Proj + "\n"
txt_Other_Proj = txt_Other_Proj + "Candida Cookbook"
txt_Other_Proj = txt_Other_Proj + "\n"
txt_Other_Proj = txt_Other_Proj + "Living with Candida Albicans"
txt_Other_Proj = txt_Other_Proj + "\n"
txt_Other_Proj = txt_Other_Proj + "Visit www.Jessit.com"
main_Info.text = txt_Other_Projhttps://stackoverflow.com/questions/8443013
复制相似问题