ios - 在 UITableViewCell Xcode StoryBoard 中调整标题

标签 ios objective-c xcode uitableview xcode-storyboard

我想在我的单元格原型(prototype)中移动标题 TextView 的位置。当我选择“标题”时,我无法调整 X、Y 坐标甚至宽度和高度。我们是否不允许自定义这部分单元格。

当我尝试在代码中执行此操作时,它说不允许我访问当前参数。如何移动此标题和副标题的位置。我想将它移到单元格的顶部,并在下面显示我的彩色 View 。提前致谢,对 Xcode 还是有些陌生。

   cell.textLabel.frame.origin.x = 30;  //not allowed to access

enter image description here

最佳答案

您无法访问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/

相关文章:

ios - 基于导航的应用程序,支持尺寸类别和 iOS 8

iphone - MKMapView 和 addOverlay - 从 kml 解析覆盖

ios - 如何使用按钮更改高度限制?

ios - XCode PhoneGap 本地化

ios - UIPanGestureRecognizer 有时不会进入最终状态

ios - 在 iOS 应用程序 (Swift) 中使用 telegram 分享消息

ios - ViewController 加载两次 xcode iOS

ios - 而 dispatch_sync(kBgQueue, ^{});在后台使用前台 UI 瞬间卡住

objective-c - 如何在基于 View 的 NSTableView 中绑定(bind) NSButton 的点击 Action

ruby - 类 SpecificationPolicy 的父类(super class)不匹配