开发者

UITableView sections text alignment

can someone help me with text alignment to the right in my uitableview开发者_运维百科 sections ?

the defult alignment is left. if the only way is to build custom header i will appreciate for code example.


try with this

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

it seems working for me.


Have you tried adding

cell.textLabel.textAlignment = UITextAlignRight;

to tableView:cellForRowAtIndexPath:?

As long as you are using cell.textLabel.text, and not the deprecated cell.text to set the text of the cell, this should work.

edit:

Sorry, I didn't catch that you were trying to do this with the section headers. I think you're going to have to roll your own header views, and return them using the UITableView delegate method -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;

Could take some work to get them to look like the default ones. Here is an example of someone describing how to theme the section headers: http://iphoneinaction.manning.com/iphone_in_action/2009/07/beauti.html


try this it is suitable for right to left languages

-(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;   
}

as you see in code this is the only way to align text from right to left, create a custom label, set its text property and alight the label to the right.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜