UITableView部分文本对齐

时间:2010-09-06 15:30:45

标签: iphone objective-c

有人可以帮助我在我的uitableview部分右侧显示文字对齐吗?

保留了defult对齐。 如果唯一的方法是构建自定义标题我将欣赏代码示例。

3 个答案:

答案 0 :(得分:2)

试试这个

 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
 {
    //create a uitextfield and set font you want in 
    return uitextfield ;
 }

它似乎对我有用。

答案 1 :(得分:0)

您是否尝试过添加

cell.textLabel.textAlignment = UITextAlignRight;

tableView:cellForRowAtIndexPath:

只要您使用cell.textLabel.text而不是已弃用的cell.text来设置单元格的文本,这应该可行。

编辑:

抱歉,我没有注意到您尝试使用节标题执行此操作。我认为您将不得不滚动自己的标题视图,并使用UITableView委托方法-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;

返回它们

可以采取一些工作让它们看起来像默认的。以下是有人描述如何设置标题标题主题的示例:http://iphoneinaction.manning.com/iphone_in_action/2009/07/beauti.html

答案 2 :(得分:-1)

试试这适用于从右到左的语言

-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    UILabel *lab = [[self.tableData objectAtIndex: section] valueForKey:kSectionTitleKey]; 
    lab.Text = @"right to left alignment text";

    lab.textAlignment = UITextAlignmentRight;
    return lab.text;   
}

正如您在代码中看到的,这是从右到左对齐文本的唯一方法,创建自定义标签,设置其文本属性并将标签向右下方。

相关问题