2010-07-26 83 views
1

表視圖,我可以顯示在表視圖小圖像,但我想加載PNG作爲我的表視圖中的每個細胞的BG如何做到這一點如何插入PNG圖片中的iPhone

cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil && searching==NO) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
       //cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

     /* 
     UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"Live and LearnCell" ofType:@"png"]]; 
     cell.image = img; 
     */ 

     //// FISRTS LABEL 
     cell.imageView.image = [UIImage imageNamed:@"TopCell.png"]; 

     mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(70.0, 5.0, 220.0, 15.0)] autorelease]; 

     mainLabel.tag = MAINLABEL_TAG; 

    // mainLabel.font = [UIFont systemFontOfSize:14.0]; 
     [mainLabel setFont:[UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]]; 

     mainLabel.textAlignment = UITextAlignmentLeft; 

     mainLabel.textColor = [UIColor whiteColor]; 
     mainLabel.highlightedTextColor = [UIColor greenColor]; 

    //mainLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight; 

     [cell.contentView addSubview:mainLabel]; 
} 

如何添加PNG作爲BG到這個單元格?

回答

0

cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]] autorelease];

+0

非常感謝; 0 – ram 2010-07-26 09:43:25

+0

嘿如果我必須合併2圖像讓我們說只有1個單元格的頂部和底部圖像??? – ram 2010-07-26 09:46:45

+0

用特定的詳細信息打開一個新問題。 – 2010-07-26 10:05:45

0

看一看的UITableViewCellbackgroundView財產。您可以將PNG加載到UIImageView中,並將其設置爲您手機的背景。

如果你想設置你的背景UITableView,它也有一個backgroundView屬性。

+0

完美泰克爲你很多啤酒 – ram 2010-07-26 09:42:50