开发者

how to insert png image in table view for iphone

i can show small image in table view but i want to load a png as a BG of each cells of my table view how to do that

   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];
         ma开发者_JAVA百科inLabel.highlightedTextColor = [UIColor greenColor];

    //mainLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;

        [cell.contentView addSubview:mainLabel];
}

how to add PNG as BG to this cell??


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


Have a look at the backgroundView property of UITableViewCell. You can load your PNG into a UIImageView and set it as the background of your cell.

If you want to set the background of your UITableView, it also has a backgroundView property.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜