我必须显示一些文本(动态),它们位于三个字符串变量中,如下所示:
SanFransisco,California 32122 ie city,state 邮政编码
所以想在三个标签中显示它们。但我不明白什么时候使用 sizetoFit 什么时候不使用。如果它是一个大文本,BrightWood Park,District of Columbia 32123
那么我得到它就像BrightWood Park,District of Columb
。我在模拟器上看不到邮政编码部分。所以无论文本可能是什么,它都应该显示在模拟器中。
如果城市的文字很大,Massachusetts Avenue Heights,District of Columbia 32123
那么它应该显示为Massachusetts Avenue Heights,District of
Columbia 32123
目前我得到了Massachusetts Avenue Heights,District of Co
NSString *city=[NSString stringWithFormat:@"%@,",self.city];
CGSize constraint4 = CGSizeMake(250, 2000.0f);
CGSize size4=[city sizeWithFont:[UIFont fontWithName:@"Helvetica-Bold" size:12] constrainedToSize:constraint4 lineBreakMode:UILineBreakModeWordWrap];
lblCity=[[UILabel alloc] init];
[lblCity setFrame:CGRectMake(60,Lane1.frame.size.height+Lane1.frame.origin.y,size4.width,size4.height) ];
lblCity.textAlignment=UITextAlignmentLeft;
lblCity.backgroundColor=[UIColor clearColor];
lblCity.text=[NSString stringWithFormat:@"%@",city];
[lblCity setNumberOfLines:0];
lblCity.highlightedTextColor=[UIColor greenColor];
[lblCity setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
[testscroll addSubview: lblCity];
NSString *state=[NSString stringWithFormat:@"%@ ",self.state];
CGSize constraint5 = CGSizeMake(250, 2000.0f);
CGSize size5=[state sizeWithFont:[UIFont fontWithName:@"Helvetica-Bold" size:12] constrainedToSize:constraint5 lineBreakMode:UILineBreakModeWordWrap];
lblState=[[UILabel alloc] init];
[lblState setFrame:CGRectMake(lblCity.frame.origin.x+lblCity.frame.size.width,Lane1.frame.size.height+Lane1.frame.origin.y,size5.width,size5.height) ];
lblState.textAlignment=UITextAlignmentLeft;
lblState.backgroundColor=[UIColor clearColor];
lblState.text=[NSString stringWithFormat:@"%@" ,state];
[lblState setNumberOfLines:0];
lblState.highlightedTextColor=[UIColor greenColor];
[lblState setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
[testscroll addSubview: lblState];
NSString *zip=[NSString stringWithFormat:@"%@",self.zip];
CGSize constraint200=CGSizeMake(250,2000.0f);
CGSize size200=[zip sizeWithFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]constrainedToSize:constraint200 lineBreakMode:UILineBreakModeWordWrap ];
zipCode=[[UILabel alloc] init];
[zipCode setFrame:CGRectMake(lblState.frame.origin.x+lblState.frame.size.width,Lane1.frame.size.height+Lane1.frame.origin.y,size200.width,size200.height) ];
zipCode.textAlignment=UITextAlignmentLeft;
zipCode.backgroundColor=[UIColor clearColor];
zipCode.text=[NSString stringWithFormat:@"%@" ,zip];
[zipCode setNumberOfLines:0];
zipCode.highlightedTextColor=[UIColor greenColor];
[zipCode setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
[testscroll addSubview:zipCode];
2.什么时候使用sizetoFit沿着numberofLines=0,什么时候不使用?