iphone - How can I add a image for each button in the table -
how can add image each button in table
i have 8 buttons in table , want put different images each button
i have how code can modified accept 8 images
- (uiimage *)cellbackgroundforrowatindexpath:(nsindexpath *)indexpath { nsinteger rowcount = [self tableview:[self tableview] numberofrowsinsection:0]; nsinteger rowindex = indexpath.row; uiimage *background = nil; if (rowindex == 0) { background = [uiimage imagenamed:@"button01.png"]; } else if (rowindex == rowcount - 1) { background = [uiimage imagenamed:@"button02.png"]; } else { background = [uiimage imagenamed:@"button03.png"]; } return background; }
form array name of images in it.
self.imagesarray = @[@"button01.png",@"button02.png",@"button03.png",...];
and access inside tableview:cellforrowatindexpath:
or configuring cell using indexpath find corresponding image imagesarray
- (uiimage *)cellbackgroundforrowatindexpath:(nsindexpath *)indexpath { nsarray *imagesarray = @[@"button01.png",@"button02.png",@"button03.png"]; return [uiimage imagenamed:imagesarray[indexpath.row]; }
Comments
Post a Comment