2013-03-02 197 views
1

下面是我如何初始化風格細胞圖像被拉伸

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

然而,圖像設置爲電池的ImageView後,圖像被拉伸現在。原件的大小是24x24。

enter image description here

我怎樣才能使圖像的外觀造型?

回答

2

儘量不要使用ImageView的物業小區,但創建自己的ImageView並將其添加

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

原來的問題是,ImageView的屬性是If an image is set, it appears on the left side of the cell, before any label.所以細胞伸展它,因爲它是用來表現。