开发者

How to use UITextAlignment to align text in UITableViewCell to the right and left in Swift

I have to align text in table cell to right and left.I have used two plist in my application according to plist selection I have to align my text in table cell.

I try following code for that

if ([app.currentPlist isEqualToString:@"Accounting.plist"]) {
    cell.textAlignment=UITextAlignmentLeft;            
} else {
    cell.textAlignment=UITextAlignmentRi开发者_StackOverflow中文版ght;           
}


UITableViewCell doesn't have a textAlignment property. You have to set it on the cell's text label:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.text = @"Something";

    if([app.currentPlist isEqualToString:@"Accounting.plist"])
    {
        cell.textLabel.textAlignment=UITextAlignmentLeft;             
    }
    else
    {
        cell.textLabel.textAlignment=UITextAlignmentRight;           
    }

    return cell;
}


UITextAlignmentRight is deprecated, use NSTextAlignmentLeft instead

So, the code will be - cell.textLabel.textAlignment = NSTextAlignmentLeft;


In swift it is

cell.textLabel.textAlignment = NSTextAlignment.Right
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜