我有一些文本標籤的兩列。當我觸摸我的第二列的任何標籤時,如何獲得第三列標籤附加到第一列。 這裏是代碼列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