2014-07-07 2 views
0

를 나는 다음과 같은 코드를 사용하여있는 UITableViewCell에 콘텐츠를 추가하고이 코드가 작동하는 동안, 그것은에 맞게 내 이미지를 압축, 그러나- 목표 - C (엑스 코드)

NSManagedObject *device = [self.devices objectAtIndex:indexPath.row]; 
[cell.textLabel setText:[NSString stringWithFormat:@"%@", [device valueForKey:@"title"]]]; 
[[cell textLabel] setBackgroundColor:[UIColor clearColor]]; 
[[cell textLabel] setTextColor:[UIColor whiteColor]]; 
cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:[device valueForKey:@"imagename"]] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]; 

을 세포. 이미지의 상단 부분 만 표시하고 늘이거나 압축하지 않기를 원합니다.

답변

1

사용 [UIView의 setContentMode는 :]

모드는 다음과 같습니다 : 당신은 좌상을 사용할 수 있습니다

typedef NS_ENUM(NSInteger, UIViewContentMode) { 
UIViewContentModeScaleToFill, 
UIViewContentModeScaleAspectFit,  // contents scaled to fit with fixed aspect. remainder is transparent 
UIViewContentModeScaleAspectFill,  // contents scaled to fill with fixed aspect. some portion of content may be clipped. 
UIViewContentModeRedraw,    // redraw on bounds change (calls -setNeedsDisplay) 
UIViewContentModeCenter,    // contents remain same size. positioned adjusted. 
UIViewContentModeTop, 
UIViewContentModeBottom, 
UIViewContentModeLeft, 
UIViewContentModeRight, 
UIViewContentModeTopLeft, 
UIViewContentModeTopRight, 
UIViewContentModeBottomLeft, 
UIViewContentModeBottomRight, 
}; 

.

추가 : 상단 캡 높이

stretchableImage은보기에 이미지가 적합 할 것이다. 나는 당신이 당신의 심상의 최고 부분을 보여줄다는 것을 생각하지 않는다.

이미지의 윗부분 만 표시해야하는 경우이 방법을 사용하십시오.

코드의 마지막 줄을 여기로 변경하고 시도하십시오.

+0

확인. 나는 iOS 프로그래밍에 익숙하지 않다. 이것은 또 다른 코드 줄입니까, 아니면 마지막 줄의 연속입니까? –

+0

아아 stretchableImage를 사용 중입니다. 반드시 필요한가요? 그렇다면 내 대답을 편집 할 것입니다. – Ryan

+0

아니요. 필요하지 않습니다. 그것은 내가 이미지를 형식화하기 위해 거기에 넣는 것을 알고있는 유일한 것입니다. stretchableImage가 제거되었을 때 UIView 코드를 추가하는 방법으로 업데이트 할 수 있습니까? –