detailTextLabel文本对齐方式 [英] detailTextLabel textalignment

查看:163
本文介绍了detailTextLabel文本对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使单元格详细信息居中。

I am trying to get the cell detail text to be centered.

我已经阅读了所有关于此的文章,但他们似乎都在谈论旧版本。 IOS。我想我尝试了各种帖子组合,但都没有运气。

I have read all kinds of posts on this but they all seem to be talking about older versions of IOS. I think I tried every combination of posts but no luck in making it work.

[[cell detailTextLabel] setTextAlignment:UITextAlignmentCenter];

我从willDisplayCell尝试过此操作,在下面的代码中也没有用。注意我在两种方法中都尝试过的两种方法。

I tried this from willDisplayCell and also in the code below, neither works. Note 2 ways of doing this I tried in both methods.

有人知道它是否有效,还是应该创建自己的中心函数(方法)?

Does anyone know if this does work or should I create my own center function (method)?

static NSString *CellIdentifier = @"Cell";


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];    
    }


    cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18.0];


    cell.detailTextLabel.font = [UIFont  systemFontOfSize:16];


    NSMutableDictionary *curRow = [myData objectAtIndex:indexPath.row];
    cell.textLabel.text = [curRow objectForKey:@"Description"];

    cell.detailTextLabel.text = [curRow objectForKey:@"Stats"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.detailTextLabel.textAlignment = UITextAlignmentCenter;


推荐答案

如果对齐方式对您有问题,则可以创建自定义标签并向该单元格添加子视图。

If Alignment is problem for you then you can create custom labels and add subview to the cell.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    UILabel *label;
    UILabel *detailLabel;

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        label = [[[UILabel alloc] initWithFrame:CGRectMake(55, 4, 260, 20)] autorelease];
        //make Your alignments to this label
        label.font = [UIFont boldSystemFontOfSize:15.0];
        label.tag=25;

        //make Your alignments to this detail label
        detailLabel = [[[UILabel alloc] initWithFrame:CGRectMake(55, 25, 260, 15)] autorelease];
        detailLabel.font = [UIFont systemFontOfSize:13.0];
        detailLabel.tag=30;
        [cell.contentView addSubview:label];
        [cell.contentView addSubview:detailLabel];
    }
    else
    {
        label = (UILabel *)[cell.contentView viewWithTag:25];
        detailLabel = (UILabel *)[cell.contentView viewWithTag:30];
    }
    label.text =[curRow objectForKey:@"Description"];
    detailLabel.text=[curRow objectForKey:@"Stats"];
    return cell;
}

这篇关于detailTextLabel文本对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆