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
Iphone UILabels完整文本不可见_Iphone_Uilabel - Fatal编程技术网

Iphone UILabels完整文本不可见

Iphone UILabels完整文本不可见,iphone,uilabel,Iphone,Uilabel,我必须将两个UILabel(state,zipCode)并排放置在UITableView的单元格中,即California 32320。当fontsize较小时,我可以清楚地看到它们。当我增大字体大小时,我看不到州标签的最后一个字母,zipCode标签正在添加。这是我正在处理的代码: -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

我必须将两个UILabel(state,zipCode)并排放置在UITableView的单元格中,即California 32320。当fontsize较小时,我可以清楚地看到它们。当我增大字体大小时,我看不到州标签的最后一个字母,zipCode标签正在添加。这是我正在处理的代码:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

        static NSString *CellIdentifier=@"Cell";

        UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if(cell == nil)
        {
            cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault    reuseIdentifier:CellIdentifier]autorelease];

            state=[[UILabel alloc] initWithFrame:CGRectZero];
            state.tag = 116;
            state.backgroundColor = [UIColor clearColor];
            [state setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
            [state setLineBreakMode:UILineBreakModeWordWrap];
            [cell addSubview:state];


            zipCode=[[UILabel alloc] initWithFrame:CGRectZero];
            zipCode.tag = 121;
            zipCode.backgroundColor = [UIColor clearColor];
            [zipCode setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
            [zipCode setLineBreakMode:UILineBreakModeWordWrap];
            [cell addSubview:zipCode];

}

        NSString *state1=[d objectForKey:@"State"];
        CGSize constraint6=CGSizeMake(175,2000.0f);
        CGSize size6=[state1 sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12]  constrainedToSize:constraint6 lineBreakMode:UILineBreakModeWordWrap];
        state=(UILabel *)[cell viewWithTag:116];
       state.frame=CGRectMake(105, city.frame.size.height+city.frame.origin.y+5, size6.width, 10);
       [state setTextAlignment:UITextAlignmentLeft];

       [state setText:[d valueForKey:@"State"]];

        NSString *zip = [d  objectForKey:@"Zip"];

        if([zip isEqualToString:@""])
        {

           zipCode=[[UILabel alloc]initWithFrame:CGRectMake(105, 125, 320,10)];
            zipCode .font=[UIFont fontWithName:@"Helvetica" size:12];
            [zipCode setTextAlignment:UITextAlignmentLeft];
            zipCode.hidden=YES;
            [zipCode  release];            


        }
        else
        {

            NSString *zip=[d objectForKey:@"Zip"];
            CGSize constraint200=CGSizeMake(175,2000.0f);
            CGSize size200=[zip sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12]  constrainedToSize:constraint200 lineBreakMode:UILineBreakModeWordWrap];
            zipCode=(UILabel *)[cell viewWithTag:121];
            zipCode.frame=CGRectMake(13+state.frame.size.width+state.frame.origin.x, city.frame.size.height+city.frame.origin.y+5, size200.width,10);

            [zipCode setTextAlignment:UITextAlignmentLeft];
            [zipCode  setText:[d valueForKey:@"Zip"]];
            zipCode.numberOfLines=0;



        }

return cell;
}
现在我可以看到结果如下 加州32320

但是当我将字体大小减少到10时,我可以清楚地看到它们(California 32320)。但是我只需要按照我的要求将字体大小设置为12


哪里出了问题?

请将标签宽度更新为多大。并使用标签的“setNoOfLine”属性设置为2。因此,它将以两行显示文本

希望对你有帮助


干杯

您的
状态
标签的字体是
Helvetica Bold
,但在您的
sizeWithFont
中,您指定的字体是
Helvetica
。或者,您可以指定
状态。font

这样做

CGFloat lLabelWidth = [yourText sizeWithFont: factLabel.font].width;

CGRect _tempFrame=yourLabel.frame;
_tempFrame.size.width=lLabelWidth;
yourLabel.frame=_tempFrame;

希望它能帮助您……

有一个小技巧,标签会根据您的文本自动调整大小

UILabel *testLabel  =   [[UILabel alloc]initWithFrame:CGRectMake(0,0,200,40)];//set your frame
testLabel.numberOfLines =   0;//Important to add this line
testLabel.font  =   [UIFont boldSystemFontOfSize:15];//Set your font
testLabel.text  =   @"Set your text here!";
[testLabel sizeToFit]; // this line will do the trick :)

使用此代码,它将看到适合您标签大小的标签

label.adjustsFontSizeToFitWidth = YES;