UILabel文字换行不适用于iPhone?

时间:2012-10-17 06:11:01

标签: iphone xcode word-wrap

我有一个UILabel它应该显示文本多长时间。为了UILineBreakModeWordWrap的概念,但它不适合我..如果文本不适合该行,那么它应该自动出现在下一行

UILabel *lblMyLable = [[[UILabel alloc] initWithFrame:CGRectMake(10,118, 600, 40)]autorelease];
    lblMyLable.lineBreakMode = UILineBreakModeWordWrap;
    lblMyLable.numberOfLines = 0;//Dynamic
    lblMyLable.tag=1301;
    lblMyLable.backgroundColor = [UIColor clearColor];
    lblMyLable.text = [NSString stringwithformat:@"%@ %@ %@ %@ %@ %@",id,name,address,city,state,country];
    [self.view addSubview:lblMyLable];

但是在显示id,名称和地址之后剩下的部分被剪掉了..我看不到 它..我正在搜索如果不适合一行,那么它应该从第一行停止的位置开始自动跳转到下一行。我该怎么办?

3 个答案:

答案 0 :(得分:5)

NSString *str = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sh";
NSString *str1 = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sh";
NSString *str2 = @"xyz";
NSString *str3 = @"xyz";
NSString *str4 = @"xyz";
NSString *str5 = @"xyz";
NSString *str6 = @"xyz";
NSString *str7 = @"xyz";   

UILabel *lblMyLable = [[UILabel alloc] initWithFrame:CGRectMake(10,10, 200, 40)];

lblMyLable.numberOfLines = 0;

lblMyLable.backgroundColor = [UIColor clearColor];

lblMyLable.text = [NSString stringWithFormat:@"%@,%@,%@,%@,%@,%@,%@,%@",str,str1,str2,str3,str4,str5,str6,str7];

[lblMyLable sizeToFit];

[self.view addSubview:lblMyLable];

答案 1 :(得分:1)

UILable的高度太小,无法让您看到

将高度设置为大于40

的值
UILabel *lblMyLable = [[UILabel alloc] initWithFrame:CGRectMake(10,118, 600, 240)];

答案 2 :(得分:0)

这会对你有所帮助

lblMyLable.numberOfLines = 0;
lblMyLable.text = [NSString stringwithformat:@"%@ %@ %@ %@ %@ %@",id,name,address,city,state,country];
[lblMyLable sizeToFit];