2015-02-02 2 views
0

autolayout을 사용하지 않는 스토리 보드 내에서 사용자 정의 셀 프로토 타입을 설정했고 UIImageView가 셀 내부에있는 모든 문제를 해결할 수 있습니다. 내가 패딩의 비트와 함께 세포의 크기를 반영하고 싶을 때 소유. 여기 UIImageView 자동으로 다양한 높이로 사용자 정의 UITableViewCell 안에 크기 조정

는 스토리 보드 인터페이스 빌더와보기 모드의 설정이 여기

Setup

을 "규모 채우기 위해"로 설정되어 것은 내가없이 배치의 편집이나 스케일링으로 돌아갈 것입니다 이미지, 마치 애스펙트 채우기를 사용하는 것처럼 보입니다.

Result

나는 다양한 옵션을 시도하고 아무도 지금까지 나를 위해 제대로 작동하지, 내가 생각할 수있는 유일한 방법은 자동 크기 조정의 턴 세포가 어떤 아이디어를 만들 때 수동으로 자신을 사각형 설정은?

- (void)setCell:(NSDictionary*)messageData 
{ 
    [_nameLabel setText:messageData[@"name"]]; 
    [_messageLabel setText:messageData[@"message"]]; 

    [_nameLabel sizeToFit]; 
    [_messageLabel sizeToFit]; 

    UIImage *image; 
    if([messageData[@"direction"] boolValue]) 
    { 
     image= [[UIImage imageNamed:@"bubble_left"]resizableImageWithCapInsets:UIEdgeInsetsMake(18, 6, 6, 10) resizingMode:UIImageResizingModeStretch]; 
    } 
    else 
    { 
     image= [[UIImage imageNamed:@"bubble_right"]resizableImageWithCapInsets:UIEdgeInsetsMake(18, 10, 6, 6) resizingMode:UIImageResizingModeStretch]; 
    } 

    [_bubbleImage setImage:image]; 
} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    CUIChatCellTableViewCell *cell = [_chatTableView dequeueReusableCellWithIdentifier:@"CustomCell" forIndexPath:indexPath]; 

    NSDictionary *messageData = _testDataArray[indexPath.row]; 

    [cell setCell:messageData]; 

    return cell; 
} 


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    _customCell = [_chatTableView dequeueReusableCellWithIdentifier:@"CustomCell"]; 

    //configure cell 
    NSDictionary *messageData = _testDataArray[indexPath.row]; 

    [_customCell setCell:messageData]; 

    //Get height of the cell 
    CGFloat height = [_customCell.messageLabel frame].size.height+[_customCell.nameLabel frame].size.height+20; 

    return height; 
} 

답변

0

어느 쪽이든 내가 수동으로 높이를 설정하는 데 결국, 나는 자동 크기가 동작하지 않습니다 수와 나는 처음부터 다른 테스트 프로젝트를 시도하고 작동 듯, 그래서 특정 설정되어 있어야합니다 어쨌든 여기에있는 내용을 기반으로하는 각 셀은 이렇게 할 코드입니다.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    _customCell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"]; 

    //configure cell 
    CMessageInfo *messageData = _testDataArray[indexPath.row]; 

    [_customCell setCell:messageData]; 

    //Get height of the cell 
    CGFloat height = [_customCell.messageLabel frame].size.height+[_customCell.nameLabel frame].size.height+20; 

    return height; 
} 
1

설정 자동 크기 속성이 같은 프로토콜 방법을 설정하기위한 내 코드, 당신이 도움을받을 수 있습니다.

Autoresizing

관련 문제