Placing UILabels next to each other programmatically [closed]

二次信任 提交于 2019-12-23 05:26:05

问题


I have three UILabels of varying widths that I'd like to line up next to each other. How do I get update the frame's X value?

Here's what I have:

UILabel *contractLabel = (UILabel *) [cell viewWithTag:200];
contractLabel.text = [board getDisplayLevel];

UILabel *contractSuit = (UILabel *) [cell viewWithTag:201];
contractSuit.text = [board getDisplayStrain];
contractSuit.textColor = [board getDisplayStrainColor];
contractSuit.hidden = NO;
contractSuit.frame = CGRectMake(contractSuit.frame.origin.x = contractLabel.frame.origin.x + contractLabel.bounds.size.width + 3, contractSuit.frame.origin.y, contractSuit.frame.size.width, contractSuit.frame.size.height); // line 121

UILabel *contractTail = (UILabel *) [cell viewWithTag:202];
contractTail.text = [board getDisplayContract];
contractTail.hidden = NO;
contractTail.frame.origin.x = contractSuit.frame.origin.x + contractSuit.bounds.size.width + 3; // line 127

Both assignments to the frame fail with:

ViewBoards_ViewController.m:121: error: lvalue required as left operand of assignment
ViewBoards_ViewController.m:127: error: lvalue required as left operand of assignment

What am I doing wrong?


回答1:


You have a simple typo

contractSuit.frame = CGRectMake(contractSuit.frame.origin.x = contractLabel.frame.origin.x + contractLabel.bounds.size.width + 3, contractSuit.frame.origin.y, contractSuit.frame.size.width, contractSuit.frame.size.height);

should be

contractSuit.frame = CGRectMake(contractSuit.frame.origin.x + contractLabel.frame.origin.x + contractLabel.bounds.size.width + 3, contractSuit.frame.origin.y, contractSuit.frame.size.width, contractSuit.frame.size.height);


来源:https://stackoverflow.com/questions/1610572/placing-uilabels-next-to-each-other-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!