雖然不是很了不起的知識, 但也是我找了許久終於找到的答案.
要使UITableViewCell的背景換成自己喜歡的, 很簡單...
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];// 套用自己的圖片做為背景 CGRect CellFrame = CGRectMake(0, 0, 300, 60); CGRect Label1Frame = CGRectMake(10, 5, 288, 38); UILabel *lblTemp; UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease]; lblTemp = [[UILabel alloc] initWithFrame:Label2Frame]; lblTemp.backgroundColor = [UIColor clearColor];//清除預設的背景顏色 lblTemp.tag = 1; lblTemp.font = [UIFont boldSystemFontOfSize:15]; lblTemp.numberOfLines = 2; [cell.contentView addSubview:lblTemp]; [lblTemp release]; } UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1]; lblTemp1.text = @"AAAAA"; return cell; } |
