Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UILabel&x27;s号线问题_Iphone_Uilabel_Xcode4.5 - Fatal编程技术网

Iphone UILabel&x27;s号线问题

Iphone UILabel&x27;s号线问题,iphone,uilabel,xcode4.5,Iphone,Uilabel,Xcode4.5,我必须在三个字符串变量中显示一些文本(动态),如下所示: 加利福尼亚州旧金山市,邮编32122,即市,州zipCode 所以我想用三种标签来展示它们,但我不知道什么时候该用sizetoFit,什么时候不该用。 如果是像哥伦比亚特区布莱特伍德公园32123这样的大文本,那么我得到的是像哥伦比亚特区布莱特伍德公园那样的大文本。我在模拟器上看不到zipCode部分。所以不管文本是什么,它都应该显示在模拟器中 如果城市文本较大,如哥伦比亚特区马萨诸塞大道高度32123,则应显示为哥伦比亚特区马萨诸塞大道

我必须在三个字符串变量中显示一些文本(动态),如下所示:

加利福尼亚州旧金山市,邮编32122,即市,州zipCode

所以我想用三种标签来展示它们,但我不知道什么时候该用sizetoFit,什么时候不该用。 如果是像哥伦比亚特区布莱特伍德公园32123这样的大文本,那么我得到的是像哥伦比亚特区布莱特伍德公园那样的大文本。我在模拟器上看不到zipCode部分。所以不管文本是什么,它都应该显示在模拟器中

如果城市文本较大,如哥伦比亚特区马萨诸塞大道高度32123,则应显示为哥伦比亚特区马萨诸塞大道高度

                                                Columbia   32123
目前,我的身份是加州马萨诸塞大道高地

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,何时不使用

有几个要点可以让autofit
UILabel

  • 首先,必须将标签的高度设置为零

  • 在第二秒,您必须将标签“
    numberOfLines
    也设置为零

  • 最后,您必须调用
    sizeToFit
    方法

像这样:

label.frame = CGRectMake(x, y, width, 0.0f);
label.numberOfLines = 0;
[label sizeToFit];

获取字符串后,如下设置
UILabel
大小

lblCity.text=[NSString stringWithFormat:@"%@",city];
 [lblCity setNumberOfLines:0];
 [lblCity setFrame:CGRectMake(60,Lane1.frame.size.height+Lane1.frame.origin.y,size4.width,size4.height) ];
[lblCity sizeToFit]; it may be work
///在这里,我测试的工作很好,并显示整个文本

NSString *city=@"Orlando ";
    CGSize constraint4 = CGSizeMake(250, 2000.0f);
    CGSize size4=[city sizeWithFont:[UIFont fontWithName:@"Helvetica-Bold" size:12] constrainedToSize:constraint4 lineBreakMode:UILineBreakModeWordWrap];
    NSLog(@"size4.width %f height %f ",size4.width,size4.height);
   UILabel* lblCity=[[UILabel alloc] init];
    [lblCity setFrame:CGRectMake(160,16,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]];
     [lblCity sizeToFit];
    [self.view addSubview: lblCity];

但如果高度=0,则标签在模拟器上不可见。那么如何操作?如果在此之后调用
sizeToFit
它将使视图的高度达到适当的大小。这是一种魔力:)但我同意你说的话,我看不到添加到视图中并在模拟器中显示的标签。我还能做什么?但是如果我有一个像Orlando这样的小文本,那么当我这样给出时,它会显示为:Olan..当我在这里删除sizetoFit时,它会显示Orlando。我不明白何时使用sizetoFit,何时不使用?你能解释一下吗?你可以寻求帮助吗从这里如果有任何问题请告诉我…Lane1?你能告诉我框架我也这么做了,因为你编辑了代码。现在,当文本较大时,它不会显示最后一部分。在你提供的上一个代码和编辑的代码中,有很多不同。我是否应该按照特定的顺序来编辑UILabel,在文本之后,numberoflines出现了,然后又出现了其他东西?因为当我改变语句的顺序时,我的结果会有很大的不同。你能告诉我吗。我被这个特殊的概念折磨得头昏眼花。请告诉我Lane1的框架是什么?