我想在我的单元格原型(prototype)中移动标题 TextView 的位置。当我选择“标题”时,我无法调整 X、Y 坐标甚至宽度和高度。我们是否不允许自定义这部分单元格。
当我尝试在代码中执行此操作时,它说不允许我访问当前参数。如何移动此标题和副标题的位置。我想将它移到单元格的顶部,并在下面显示我的彩色 View 。提前致谢,对 Xcode 还是有些陌生。
cell.textLabel.frame.origin.x = 30; //not allowed to access
最佳答案
您无法访问x 位置,但您可以轻松放置整个框架。 这里和代码示例,我认为这是你最好的选择:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *reuseIdentifier = @"reuseIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
cell.textLabel.frame = CGRectMake(0, 0, cell.frame.size.width, 30);
cell.textLabel.backgroundColor = [UIColor greenColor];
}
// Configure your cell...
return cell;
}
这里使用 Story cell,我认为更糟糕,因为更多的工作。(它根本没有利用重用技术)。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"storyIdentifier" forIndexPath:indexPath];
cell.textLabel.frame = CGRectMake(0, 0, cell.frame.size.width, 30);
cell.textLabel.backgroundColor = [UIColor greenColor];
// Configure your cell...
return cell;
}
关于ios - 在 UITableViewCell Xcode StoryBoard 中调整标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27472583/