-2
안녕하세요 여러분, 저는 iOS 개발에 새로운입니다. 이제 맞춤 tableView에서 작업하고 있습니다.이 작업은 맞춤 tableViewCell을 사용하고 있습니다. 해당 셀에 imageView에 텍스트 레이블을 추가합니다. 하지만 이미지 뷰에 텍스트 레이블을 표시하지 않습니다. 이미지 만 보여줍니다. 누군가이 문제에 대한 해결책이 있다면 저를 도우십시오. 여기 어떻게 iOS의 사용자 정의 tableviewcell에 이미지에 텍스트 레이블을 추가 할 수 있습니까?
내가이 솔루션을 가지고 다음 열심히 노력하면 내 코드- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";
ItemsCellVC *cell = (ItemsCellVC *)[TableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ItemsCellVC alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];
UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
cellBackgroundView.image = background;
cell.backgroundView = cellBackgroundView;
if ([arrayForItemDictionary count]!=0) {
if (tableView == aSearchDisplayController.searchResultsTableView)
{
dictItemFromDatabase=[filteredListContent objectAtIndex:indexPath.row];
}
else
{
dictItemFromDatabase=[arrayForItemDictionary objectAtIndex:indexPath.row];
}
}
//cell.containerNameLabel.text=[dictItemFromDatabase valueForKey:@"PickerName"];
cell.itemNameLabel.text = [dictItemFromDatabase valueForKey:@"ItemNameTF"];
cell.containerImgView.image = [UIImage imageNamed:@"12-02 (1)"];
UIImage *image = [UIImage imageNamed:@"2-02 (1).png"];
cell.containerImgView.image = [self addText:image text:@"Hello there"];
return cell;
}
-(UIImage *)addText:(UIImage *)img text:(NSString *)text1{
int w = img.size.width;
int h = img.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
char* text= (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding];
CGContextSelectFont(context, "Arial",20, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetRGBFillColor(context, 0, 0, 0, 1);
CGContextShowTextAtPoint(context,10,10,text, strlen(text));
CGImageRef imgCombined = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
UIImage *retImage = [UIImage imageWithCGImage:imgCombined];
CGImageRelease(imgCombined);
return retImage;
}
cellforrowatindex 코드를 추가 –
u 코드를 표시 할 수 있습니다 –
최고의 wa y는 imageView 및 레이블을 사용하여 사용자 정의 셀을 만들고 셀이 초기화 될 때 하위 뷰에 추가하는 것입니다. 그런 다음 프레임을 구성 할 수 있도록 속성에 연결되어 있는지 확인하십시오. – iYoung