我有一些文本标签的两列。当我触摸我的第二列的任何标签时,如何获得第三列标签附加到第一列。 这里是代码列1和列2标签如何定位相对于与触摸其他标签的标签的五个人副本的目标C
column1的标签
for(int i=0;i<length;i++)
{
_lbl = [[UILabel alloc]initWithFrame:rect1];
// lbl.frame=CGRectMake(x, y, width+10, 30);
_lbl.center = CGPointMake(x, y);
_lbl.tag=i;
_lbl.textAlignment=NSTextAlignmentCenter;
_lbl.backgroundColor=[UIColor blueColor];
_lbl.textColor=[UIColor whiteColor];
_lbl.font = [UIFont fontWithName:@"Verdana-Bold" size:17.0];
//label.clipsToBounds=YES;
//label.layer.cornerRadius=5.0;
[self.gameLayer addSubview:_lbl];
_lbl.userInteractionEnabled = YES;
[email protected]"Text1";
[_lbl sizeToFit];
列2为标签
for(int i=0;i<length;i++)
{
_lbl2 = [[UILabel alloc]initWithFrame:rect];
// _lbl2.frame=CGRectMake(x, y, width+10, 30);
_lbl2.center = CGPointMake(x+20, y);
_lbl2.tag=i+5;
_lbl2.textAlignment=NSTextAlignmentCenter;
_lbl2.backgroundColor=[UIColor greenColor];
_lbl2.textColor=[UIColor whiteColor];
_lbl2.font = [UIFont fontWithName:@"Verdana-Bold" size:17.0];
//_lbl2.clipsToBounds=YES;
//_lbl2.layer.cornerRadius=5.0;
[self.gameLayer addSubview:_lbl2];
_lbl.userInteractionEnabled = YES;
[email protected]"Text2";
[_lbl2 sizeToFit];
在触摸Begin方法我调用一个方法makeThirdColumn
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint pt = [[touches anyObject] locationInView:self.superview];
_xOffset = pt.x - self.center.x;
_yOffset = pt.y - self.center.y;
[self makeThirdColumn];
我想与COLUMN1文本1标签的第三列concate。
基于您的代码......首先,创建5个标签没有文字,所以只是简单的绿色长方形,都在彼此的顶部,这样的结果就是One绿色框。其次,您也可以对5个红色标签进行相同处理,并重新放在另一个上面,从而产生一个红色框。第三,你通过设置框,然后改变坐标系的原点,然后改变整个帧,再对所有彼此的顶部创建5个标签,每个时间。另外...你不会创建任何对你添加的标签的引用,所以在“第三行”中没有label1或label2。 – DonMag
我会建议---第一步:编写正确创建前两个“行”标签的代码。然后编辑显示*代码的问题,再加上它的外观图像,并显示您希望显示第三行标签的位置。 – DonMag
哦,我看到它让我更新我的代码 – Flying