したがって、カスタムセルクラスがあり、実装には次のコードがあります。
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame = CGRectMake(boundsX+10,10, 50, 50);
picture.frame = frame;
frame = CGRectMake(boundsX+75 ,0, 170, 50);
nameLabel.frame = frame;
frame = CGRectMake(boundsX+75 ,43, 225, 23);
costLabel.frame = frame;
frame = CGRectMake(boundsX+280, 30, 8, 13);
arrow.frame = frame;
}
次の図で、このレイアウトがどのように機能するかを見てみましょう。
結果には満足していますが、 nameLabelに従ってセル内のcostLabelの位置も変更したいと思います。nameLabelに2つのテキストがある場合、costLabelの位置を変更したくありませんが、nameLabelにテキストが1つしかない場合は、 costLabelを上に移動して、スペースを削除してcostLabelを作成できます。 nameLabelに近い。lines
line
私はcellForRowAtIndexPathでこれを試しました:
CGRect frame = cell.costLabel.frame;
frame.origin.y = frame.origin.y-10; // new y coordinate
cell.costLabel.frame = frame;
しかし、それはうまくいきませんでした。
解決策やアイデアはありますCGRect
か?座標(y原点)を変更するにはどうすればよいですか?