문제

표준이 있습니다 UITableViewCell 텍스트와 이미지 속성을 사용하여 favicon.ico 그리고 레이블. 대부분의 경우, 이것은 그 이후로 정말 잘 작동합니다. UIImage ICO 형식을 지원합니다. 그러나 일부 사이트 (예 : Amazon.com 말하라 favicon.ico동일한 파일에 여러 크기를 저장할 수있는 ICO 형식의 기능을 사용하는 s. 아마존은 최대 48x48까지 4 가지 크기를 저장합니다.

이로 인해 대부분의 이미지는 32x32 또는 48x48로 들어오고 모든 것을 끔찍하게 보이게하는 몇 가지를 제외하고 16x16입니다. 나는 여기서, 공식 포럼, 문서 및 다른 곳에서 성공하지 못했습니다. 이미지 크기를 제한하기 위해 생각할 수있는 모든 것을 시도했습니다. 작동 한 유일한 것은 문서화되지 않은 방법으로 사용하지 않습니다. 이것은 나의 첫 번째 앱이자 Cocoa에 대한 첫 경험입니다 (C#에서 나왔습니다).

내가 찾고있는 것이 명확하지 않은 경우, 이상적으로는 조언이 UIImage 48x48 버전이 16x16으로 축소되거나 알려주는 방법 UIImage ICO 파일에있는 16x16 버전을 사용합니다. 반드시 코드가 필요하지는 않습니다. 접근 방식에 대한 제안은 괜찮을 것입니다.

누구든지 제안이 있습니까? (공식 포럼에서 물었습니다 또한 나는 이미 이것에 하루 이상 가라 앉았 기 때문입니다. 해결책이 거기에 게시되면 여기에도 넣을 것입니다.)

도움이 되었습니까?

해결책

공식 포럼에서 사용자 "BCD"가 무엇인지 다음은 다음과 같습니다. 게시 이로 인해 문제를 해결하게되었습니다 (유틸리티 방법에 포함시키기 위해 정적으로 만들기 위해 약간의 수정으로) :

+ (UIImage *)scale:(UIImage *)image toSize:(CGSize)size
{
    UIGraphicsBeginImageContext(size);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return scaledImage;
}

다른 팁

내 앱에서 비슷한 일을하고 있습니다.

    UIImage* resizedImage(UIImage *inImage, CGRect thumbRect)
{
    CGImageRef          imageRef = [inImage CGImage];
    CGImageAlphaInfo    alphaInfo = CGImageGetAlphaInfo(imageRef);

    if (alphaInfo == kCGImageAlphaNone)
        alphaInfo = kCGImageAlphaNoneSkipLast;

    CGContextRef bitmap = CGBitmapContextCreate (NULL, thumbRect.size.width, thumbRect.size.height, 8, thumbRect.size.width*3, 
                                                                                 CGColorSpaceCreateDeviceRGB(), alphaInfo);

    CGContextDrawImage(bitmap, thumbRect, imageRef);

    CGImageRef  ref = CGBitmapContextCreateImage(bitmap);
    UIImage*    result = [UIImage imageWithCGImage:ref];

    CGContextRelease(bitmap);
    CGImageRelease(ref);

    return result;
}

그런 다음 비율을 제한하는 새 이미지를 만듭니다. "이미지"를 Amazon에서 얻는 ICO 파일로 대체합니다.

CGRect sz = CGRectMake(0.0f, 0.0f, 16, 16);
UIImage *resized = resizedImage(image, sz);

답변에 대해서는 아직 충분한 업장이 없지만 위의 Bbrandons 코드에서는 성공을 거두었습니다.

행당 설정 당 바이트 설정에 대해 충분히 높지 않은 것에 대해 콘솔에서 상당한 수의 경고를 받았습니다. 게시하다 결국 0으로 설정하여 시스템이 올바른 값을 결정할 수 있습니다.

예 :

CGContextRef bitmap = CGBitmapContextCreate(NULL, size.width, size.height, 8, 0, CGColorSpaceCreateDeviceRGB(), alphaInfo);

내가 한 방법은 다음과 같습니다. 이 기술은 텍스트와 세부 사항 텍스트 레이블을 왼쪽으로 적절하게 이동해야합니다.

@interface SizableImageCell : UITableViewCell {}
@end
@implementation SizableImageCell
- (void)layoutSubviews {
    [super layoutSubviews];

    float desiredWidth = 80;
    float w=self.imageView.frame.size.width;
    if (w>desiredWidth) {
        float widthSub = w - desiredWidth;
        self.imageView.frame = CGRectMake(self.imageView.frame.origin.x,self.imageView.frame.origin.y,desiredWidth,self.imageView.frame.size.height);
        self.textLabel.frame = CGRectMake(self.textLabel.frame.origin.x-widthSub,self.textLabel.frame.origin.y,self.textLabel.frame.size.width+widthSub,self.textLabel.frame.size.height);
        self.detailTextLabel.frame = CGRectMake(self.detailTextLabel.frame.origin.x-widthSub,self.detailTextLabel.frame.origin.y,self.detailTextLabel.frame.size.width+widthSub,self.detailTextLabel.frame.size.height);
        self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    }
}
@end

...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[SizableImageCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    cell.textLabel.text = ...
    cell.detailTextLabel.text = ...
    cell.imageView.image = ...
    return cell;
}

ICO 파일의 작동 방식에 대해 아무것도 모르겠으므로 16x16 이미지를 손으로 추출하여 사용하는 것이 가능하지만 방법은 모릅니다.

내가 아는 한, 일반적인 이미지에서 유용한 속성을 설정할 수 없습니다. UITableViewCell. 모든 것을 16x16으로 확장하는 가장 간단한 방법 (특히 처음에는 지저분한 경우)은 서브 클래스입니다. UITableViewCell, 그것을 줘 UIImageView, 항상 이미지보기를 16x16으로 크기를 크기로 만들고 Contentmode를 UIViewContentModeAspectFit.

나는 모든 이미지가 스케일링없이 동일한 너비 (가시 너비)를 차지하기 위해 다른 사람들의 사람 카테고리를 수정했습니다.

-(UIImage*) centerImage:(UIImage *)inImage inRect:(CGRect) thumbRect
{

    CGSize size= thumbRect.size;
    UIGraphicsBeginImageContext(size);  
    //calculation
    [inImage drawInRect:CGRectMake((size.width-inImage.size.width)/2, (size.height-inImage.size.height)/2, inImage.size.width, inImage.size.height)];
    UIImage *newThumbnail = UIGraphicsGetImageFromCurrentImageContext();        
    // pop the context
    UIGraphicsEndImageContext();
    return newThumbnail;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top