For this you will have to restrict the width of default textLabel of UITableViewCell or add new UILabel to cell.
you have two options
1)Dont use default textLabel of cell, create new UILabel and add it as a subview of tableview cell.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell using custom cell
//restrict width here while creating label (change 40 to what you want)
UILabel *tempLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,0,40,20)];
tempLabel.text=@"The text you want to assign";
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[[cell contentView] addSubview:tempLabel];
}
return cell;
}
2)Or second way is to change width of default textLabel , for this you will have to create new subclass inheriting UITableViewCell, and in the subclass override method (void)layoutSubView and in that method change width(do it by trial and error method)
create new class with following .h and .m file
////CustomCell .h file
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell
@end
////CustomCell .m file
#import "CustomCell.h"
@implementation CustomCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
-(void)layoutSubviews{
[super layoutSubviews];
CGRect tempFrame=self.textLabel.frame;
//whatever you want to set
tempFrame.width=30;
self.textLabel.frame=tempFrame;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
Or one different option(better one)
3) Create custom tableview cell
custom tableview cell tutorial
And for having ... at the end of UILabel, there is property truncateTail of UILabel. you can use that.