0

我想实现以下目标:

  1. 我有两个数组

     NSMutableArray *languageArray=[[NSMutableArray alloc]initWithObjects:@"Chinese bla blub",@"Spanish",@"English",@"Arabic",@"Hindi",@"Bengali",@"Portuguese",@"Russian",@"Japanee",@"German",@"German",@"German",@"German",@"German",nil];
    
     NSMutableArray *languageArray2=[[NSMutableArray alloc]initWithObjects:@"Hier kommt nun was ganz langes, jetzt mach ich das noch länger, damit der scheiß auch wirklich funktioniert.",@"Spanish jetzt hist hier auch mehr drin das sieht ja super aus wieviel bekomme ich den hier rein ",@"English",@"Arabic",@"Hindi",@"Bengali",@"Portuguese",@"Russian ajkslasdöadfnaklsdmnklsd",@"Japanese",@"German",@"German",@"German hier steht jetzt was ganz langes drin",@"German",@"German",nil];
    
  2. 我有一个UIScrollView

  3. 如您所见,我ObjectAtIndex:0在两个数组中的内容和长度都不同

  4. 我想为 My Array 中的每个 Object 设置一个标签,该标签用于 Array 1 屏幕的左侧站点,另一个从标签 1 的末尾开始。

喜欢这张照片。

看到这个链接

我怎么做?

4

1 回答 1

0

您可以UILable使用我的这个方法设置动态高度:

-(float) calculateHeightOfTextFromWidth:(NSString*) text: (UIFont*)withFont: (float)width :(UILineBreakMode)lineBreakMode
{
[text retain];
[withFont retain];
CGSize suggestedSize = [text sizeWithFont:withFont constrainedToSize:CGSizeMake(width, FLT_MAX) lineBreakMode:lineBreakMode];

[text release];
[withFont release];

return suggestedSize.height;
}

并像下面这样使用它:

UILabel *lblAddress = [[UILabel alloc]init];
[lblAddress setFrame:CGRectMake(110, 31, 200, 50)];        
lblAddress.text = @"your Text ";
lblAddress.lineBreakMode = UILineBreakModeWordWrap;
lblAddress.numberOfLines = 0;
lblAddress.font = [UIFont fontWithName:@"Helvetica" size:12];

lblAddress.frame = CGRectMake(lblAddress.frame.origin.x, lblAddress.frame.origin.y, 
                         200,[self calculateHeightOfTextFromWidth:lblAddress.text :lblAddress.font :200 :UILineBreakModeWordWrap] ); 

lblAddress.textColor = [UIColor darkGrayColor];

[self.view addSubview:lblAddress];

然后UIScrollView's像下面这样设置内容大小..

float fscrview = lblAddress.frame.origin.y + lblAddress.frame.size.height + 20;
yourScrollView.contentSize=CGSizeMake(320, fscrview);
于 2013-03-28T12:26:23.463 回答