2013-02-28 53 views
1

enter image description here我正在創建一個UILabel,用於在iphone應用程序中顯示約16,000行的文本。它早期對ios 6工作正常,但現在在iOS 6.0或更高版本中它沒有正確顯示。 =UILabel在iPhone應用程序中沒有顯示非常大的文本

infoUILabel.text = stringForLargeDescrition; 
CGSize constraintSize; 
    constraintSize.width = 285.0f; 
    constraintSize.height = MAXFLOAT; 

stringSizeforDescription = [strignForLabel sizeWithFont: [UIFont boldSystemFontOfSize: 5] constrainedToSize: constraintSize lineBreakMode: UILineBreakModeWordWrap]; 
     infoUILabel.layer.cornerRadius = 10;  
     infoUILabel.layer.masksToBounds = YES; 
     [infoUILabel setFrame:CGRectMake(20,135, 285, stringSizeforDescription.height)]; 
     CGRect frame = infoUILabel.frame; 
     frame.size = [infoUILabel sizeThatFits:CGSizeMake(285, stringSizeforDescription.height)]; 
     infoUILabel.frame = frame; 
     [infoUILabel alignTop];//this function will align the text to top of label 
     backScrollView.contentSize = CGSizeMake(320, 230 + infoUILabel.frame.size.height); 
    backScrollView.clipsToBounds = YES; 

沒有在label.It越來越顯示被正確早些時候工作,不知道什麼在它。我去錯了添加的UILabel上Scrollview.Code的標籤下面給出請提前建議,謝謝。

+4

的UITextView .....,有沒有原因您使用的是標籤而不是textview – Bergasms 2013-02-28 05:56:46

+1

同意@Bergasms – 2013-02-28 05:58:26

+0

UITextView更適合用於顯示大量數據的UILabel選項。它還提供了滾動功能,如果是標籤,則需要自行處理。 – Sagrian 2013-02-28 05:59:08

回答

2

的TextView顯示動態文本解決了我的問題的用途,是作爲下面給出代碼:

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 135, 285, 200)]; 
    textView.text = @"Very large text"; 
    textView.scrollEnabled = NO; 
    textView.delegate = self; 
    textView.font = [UIFont fontWithName:@"Helvetica" size:12.0f]; 
    textView.textColor = [UIColor darkGrayColor]; 
    textView.layer.cornerRadius = 10; 
    textView.layer.masksToBounds = YES; 
    textView.backgroundColor= [UIColor whiteColor]; 
    CGRect rect  = textView.frame; 

CGSize constraintSize; 
constraintSize.width = 285.0f; 
constraintSize.height = MAXFLOAT; 
stringSizeforDescription = [strignForLabel sizeWithFont: [UIFont boldSystemFontOfSize: 12] constrainedToSize: constraintSize lineBreakMode: UILineBreakModeWordWrap]; 
    rect.size.height = stringSizeforDescription.height + 20;//20 is some extra margin value 
    textView.frame = rect; 

[scrollView addSubview:textView]; 
[textView sizeToFit]; 
1

您錯過了要設置的numberOfLines屬性。

地址:

infoUILabel.numberOfLines = 0; 

它應該工作。同時刪除您的代碼這兩條線:

frame.size = [infoUILabel sizeThatFits:CGSizeMake(285, stringSizeforDescription.height)]; 
infoUILabel.frame = frame; 
+0

我已經嘗試過這種方法,但它並不按照我想要的方式工作。 – iphonedeveloper 2013-02-28 07:20:31

+0

@ user378084你可以添加你所得到的屏幕截圖嗎? – Rushi 2013-02-28 07:22:29

0

添加

infoLabel.numberOfLines=0; 

確保該MAXFLOAT比預期

+0

MaxFloat大於預期 – iphonedeveloper 2013-03-04 06:46:35

0

一個更大的值能否請您嘗試設置文本的UILabel最後......在爲UILabel設置了所有屬性之後。

+0

我在問題中添加了圖像,白色背景已被賦予uiLabel,並且屏幕與背景中的圖像一起顯示。透明滾動視圖被添加到UILabel的背景中。 – iphonedeveloper 2013-03-01 10:04:59

0

試試這個,它的工作對我來說:

CGFloat height = 44.0; 

CGSize labelSize = CGSizeMake(200.0, 20.0); 

NSString *strTemp; 

NSString *sectionData = @"Lengthy text.......Lengthy text.......Lengthy text......."; 

labelSize = [sectionData sizeWithFont: [UIFont boldSystemFontOfSize:12.0] constrainedToSize: CGSizeMake(labelSize.width, 1000) lineBreakMode: UILineBreakModeWordWrap]; 

height = (labelSize.height+40); 

CGRect rect = lbl.frame; 

rect.size.height = height; 

lbl.frame = rect; 
相關問題