Question

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?

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top