tranvutuan
tranvutuan

Reputation: 6109

image of uitableviewcell is stretching

Below is how I initialize the style for a cell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        .................................................
        .................................................
        // Set size for imageView
        CGRect  frame               =   self.imageView.frame;
        frame.size.width            =   16;
        frame.size.height           =   16;
        self.imageView.frame        =   frame;
    }

    return self;
}

However, after setting an image to imageview of a cell, the image is stretching now. The size of original is 24x24.

enter image description here

How can I make an image look shape ?

Upvotes: 1

Views: 541

Answers (1)

B.S.
B.S.

Reputation: 21726

Try not to use imageView property of the cell, but create your own imageview and add it

UIImageView *myImageView = [[UIImageView alloc] initWithImage:neededImage];
myImageView.frame = CGRectMake(0,0,16,16);
[self addSubview:myImageView];
[myImageView release];

The original problem is that imageView property is If an image is set, it appears on the left side of the cell, before any label. So cell stretches it as it is used to behave.

Upvotes: 2

Related Questions