Ios UITableViewCell中的文本对齐方式
我为我的通用应用程序制作了自定义单元格。在iPhone中,屏幕文本是正常的,但当我移动到iPad时,屏幕文本从最左边开始(如下图所示)。我怎样才能把它移对一点(可能是10px)。是否有方法从Ios UITableViewCell中的文本对齐方式,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我为我的通用应用程序制作了自定义单元格。在iPhone中,屏幕文本是正常的,但当我移动到iPad时,屏幕文本从最左边开始(如下图所示)。我怎样才能把它移对一点(可能是10px)。是否有方法从-(UITableViewCell*)tableView:(UITableView*)tableView cell for rowatinexpath:(nsindepath*)indepath中的10px开始文本标签 方法?提前谢谢 - (UITableViewCell *)tableView:(UITab
-(UITableViewCell*)tableView:(UITableView*)tableView cell for rowatinexpath:(nsindepath*)indepath中的10px开始文本标签
方法?提前谢谢
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell2";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [firstArray objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.numberOfLines = 0;
[cell.textLabel setLineBreakMode:NSLineBreakByWordWrapping];
UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, cell.bounds.size.width);
UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
cellBackgroundView.image = background;
cell.backgroundView = cellBackgroundView;
return cell;
}
如果要覆盖字段中插入的文本,请覆盖'-editingRectForBounds:'
- (CGRect)editingRectForBounds:(CGRect)bounds {
return CGRectInset( bounds , 10 , 10 );
}
如果要在单元内移动标签,可以创建自定义UITableViewCell类并覆盖LayoutSubView
- (void) layoutSubviews {
[super layoutSubviews];
self.textLabel.frame = CGRectMake(10, 0, 310, 20);
}
单元格可以这样初始化
cell = [[YOUR_CUSTOM_CELL_CLASS alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
编辑
在表视图控制器中:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Dequeue if possible of course
UITableViewCell *cell = [[CustomCellClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Identifier"];
cell.textLabel.text = @"Should be indented";
return cell;
}
在CustomCellClass中:
-(无效)布局子视图{
[超级布局子视图];
self.textlab.frame=CGRectMake(100,0,310,20);
}
然后文本标签将缩进100点:)
资料来源:
刚刚做的你现在如何设置你的手机?发布一些如何创建自定义单元格的代码。我创建了一个自定义单元格类并覆盖了LayoutSubview,但它不起作用。