开发者

Placing UILabels next to each other programmatically [closed]

开发者 https://www.devze.com 2022-12-09 11:30 出处:网络
开发者_C百科 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not gene
开发者_C百科 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

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?


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

精彩评论

暂无评论...
验证码 换一张
取 消