开发者

moving label to centre of cell

i have created my label using this

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

i want to move my label to centre of the cell... can any one answer it.... t开发者_开发百科hank you for valuable answers...


The cell's center point is in the cell.superview's coordinates, just convert that point to the cell's coordinates and set the label's center there:

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


just set the labels frame to the appropriate offset :

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


Below code adds a label to the center of a collection view cell.

// 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];

Hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜