2012-10-17 108 views
0

我有一個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看到 它..我正在尋找這樣的方式後,如果不列入符合一條線,那麼它應該自動跳到下一行,從第一行停止的位置開始。我該怎麼辦?

回答

4
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中編寫行的行列並檢查它。它的工作完美。 –

0

這將幫助你

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

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

1

UILable的HIGHT太小,讓你看到

設定的高度線到vialue大於40

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

雖然它不工作g – Honey