UILabel文本换行在iPhone中不起作用?

问题描述:

我有一个UILabel,它应该显示文本多长时间,所以去了UILineBreakModeWordWrap的概念,但它不适合我。如果文本不适合该行,那么它应该会自动出现在下一行UILabel文本换行在iPhone中不起作用?

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,姓名和地址的其余部分被切除..我couldnot看到 它..我正在寻找这样的方式后,如果不列入符合一条线,那么它应该自动跳到下一行,从第一行停止的位置开始。我该怎么办?

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]; 
+0

@arizah:工作正常。一旦你请检查出来.. –

+0

@arizah:在lblMyLable.text中编写行的行列并检查它。它的工作完美。 –

这将帮助你

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

它不工作。我得到像以前一样的 – Honey

UILable的HIGHT太小,让你看到

设定的高度线到vialue大于40

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

虽然它不工作g – Honey