2010-06-14 126 views
1

的中心我一直在使用這個移動標籤細胞

UILabel *label1 = (UILabel *) [cell viewWithTag:1]; 

我想我的標籤移動到細胞的中心...... 任何一個可以回答這個問題建立了我的標籤.... 謝謝對於有價值的答案...

回答

0

剛纔設置的標籤幀到合適的偏移:

x=cell.frame.width/2-label1.frame.width/2; 

y=cell.frame.height/2-label1.frame.height/2; 

label1.frame=CGRectMake(x,y,cell.frame.width,cell.frame.height); 
1

單元格的中心點是在cell.superview座標,只是轉換THA t指向單元格的座標並在此處設置標籤的中心:

label1.center = [cell.superview convertPoint:cell.center toView:cell]; 
0

下面的代碼向集合視圖單元格的中心添加一個標籤。

// self is the current cell. 
UILabel *pointLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 
pointLabel.textAlignment = NSTextAlignmentCenter; 
pointLabel.textColor = [UIColor yellowColor]; 
pointLabel.text = @"+300"; 
[self addSubview:pointLabel]; 

希望這會有所幫助。