UITableView
, UITableViewCell (?) 셀에 UIImage
을 끼워 넣는 방법. UITableView 셀에 맞게 이미지의 크기를 조정하는 방법은 무엇입니까?
addSubview
cell
에 작업을 수행하거나이
cell.image
에 할당되기 전에
cell.image
또는
UIImage
의 크기를 조정하는 방법은 무엇입니까?
셀 크기를 기본값으로 유지하고 싶습니다. (제로 사각형으로 초기화 할 때 어떤 것이 든) 각 항목에 그림과 같은 아이콘을 추가하고 싶습니다. 이미지는 셀 크기 (테이블 행 크기)보다 약간 큽니다.
나는 코드가 (내 머리의 꼭대기에서) 다음과 같습니다 생각 :
나는 셀 크기에 맞게 이미지 크기를 조정하려면 어떻게해야합니까 무엇UIImage * image = [[UIImage alloc] imageWithName:@"bart.jpg"];
cell = ... dequeue cell in UITableView data source (UITableViewController ...)
cell.text = @"bart";
cell.image = image;
? 내가 좋아하는 것을 본 적이 :
UIImageView * iview = [[UIImageView alloc] initWithImage:image];
iview.frame = CGRectMake(...); // or something similar
[cell.contentView addSubview:iview]
위의 셀에 이미지를 추가 할 것입니다 내가하지만,에 맞게 크기를 계산할 수 있습니다
- 는 잘 모르겠어요 더 나은가있는 경우 방법, 너무 많은 오버 헤드가 아닌 그냥 크기를 조정하려면
cell.image
?
예 :
cell.text
는) 그것이 이미지에 의해 가려 한, 내가 방금 레이블로 텍스트를 추가하는 솔루션을 본 적이 이동해야 UILabel * text = [[UILable alloc] init];
text.text = @"bart";
[cell.contentView addSubview:iview];
[cell.contentView addSubview:label];
// not sure if this will position the text next to the label
// edited original example had [cell addSubview:label], maybe that's the problem
누군가 올바른 방향으로 나를 가리킬 수 있습니까?
편집 : 도현 [cell.contentview addSubview:view]
는 어쩌면 나는이보고되어있어하지 [cell addSubview:view]
:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = ...;
CGRect frame = cell.contentView.bounds;
UILabel *myLabel = [[UILabel alloc] initWithFrame:frame];
myLabel.text = ...;
[cell.contentView addSubview:myLabel];
[myLabel release];
}
다른 제안이 없습니까? – stefanB