OGeek|极客世界-中国程序员成长平台

标题: iphone - UITableView 中的 UILabel 设置大小 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 22:15
标题: iphone - UITableView 中的 UILabel 设置大小

我想将标签 subview 添加到 UITableViewCell。我可以轻松地将框架原点和大小设置为特定值,但如何使用当前/默认单元格标签高度和位置?

  UILabel *labPerHour;

  cell.textLabel.text       = @"Rate";

  labPerHour = [[UILabel alloc] init];

  //labPerHour.frame = CGRectMake( 280, cell.textLabel.frame.origin.y, 80, cell.textLabel.frame.size.height );
  labPerHour.frame = CGRectMake( 260, 7, 30, 30 );
  labPerHour.text  = @"$/hr";


  [cell addSubview:labPerHour];

我希望注释掉的行可以工作..或类似的东西。

有人可以帮忙吗?这段代码当然是我的 cellForRowAtIndexPath 方法的一部分。



Best Answer-推荐答案


我不确定。也许它会起作用。这个我没试过!!

CGRect theFrame = cell.textLabel.frame;
theFrame.origin.x = 280;
theFrame.size.width = 80;
labPerHour.frame = theFrame;

关于iphone - UITableView 中的 UILabel 设置大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11737199/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4