以编程方式将UILabel放在一起

时间:2009-10-22 23:23:38

标签: iphone uiview uilabel

我有三个不同宽度的UILabel,我想彼此相邻排列。如何更新帧的X值?

这就是我所拥有的:

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

对帧的两次分配均失败:

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

我做错了什么?

1 个答案:

答案 0 :(得分:2)

你有一个简单的拼写错误

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);

应该是

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);