我需要对我的项目提供帮助。 我想实现以下目标:
我有两个数组
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];
我有UIScrollView
正如您所见,两个数组中的ObjectAtIndex:0
内容和长度不同
我想为My Array中的每个Object设置一个标签,用于阵列1,屏幕的左侧站点,另一个标签从标签1的末尾开始。
喜欢这张照片。 See this link 我怎么做? 有一个简单的方法吗? 感谢
答案 0 :(得分: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);
我希望这对你有帮助......