내가 뭘하려고했는지 UIImageView 어둡게 이미지 및 결과의 상단에있는보기가 있도록했다. 나는 ios6에서 사용자가 Facebook을 사용하여 공유 할 때 부여되는 효과를주고 싶었습니다. 그 뒤에있는 모든 콘텐츠는 더 어두워 지지만 표시됩니다. 사용해 보았습니다 :어둡게 UIImageView IOS
UIImage *maskedImage = [self darkenImage:image toLevel:0.5];
- (UIImage *)darkenImage:(UIImage *)image toLevel:(CGFloat)level
{
// Create a temporary view to act as a darkening layer
CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
UIView *tempView = [[UIView alloc] initWithFrame:frame];
tempView.backgroundColor = [UIColor blackColor];
tempView.alpha = level;
// Draw the image into a new graphics context
UIGraphicsBeginImageContext(frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[image drawInRect:frame];
// Flip the context vertically so we can draw the dark layer via a mask that
// aligns with the image's alpha pixels (Quartz uses flipped coordinates)
CGContextTranslateCTM(context, 0, frame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextClipToMask(context, frame, image.CGImage);
[tempView.layer renderInContext:context];
// Produce a new image from this context
CGImageRef imageRef = CGBitmapContextCreateImage(context);
UIImage *toReturn = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
UIGraphicsEndImageContext();
return toReturn;
}
그러나 원하는 효과를 내지 못합니다. 그것은 ios facebook 공유를 사용할 때처럼 어두워지기를 원하는 반면, 색상은 바뀌고 배경은 어두워집니다. 이것이 가능한가?
알파를 적절한 수준으로 설정하여 맨 위에 새 (검은 색 채우기)보기를 배치하지 않는 이유는 무엇입니까? (추측 하건데, 이것은 UIImage를 조작하는 것보다 자원 집약적 인 것 같아요. 예, 이것은 필요한 테스트 없이는 의미가 없지만 거기에 있습니다.) –
@middaparka가 제시 한 제안을 사용했습니다. 그리고 그것은 괜찮습니다 (당신이 페이스 북 공유를 통해 얻을 수있는 멋진 방사형 그래디언트를 원하지 않는 한). 원하는 경우 맞춤보기를 만들어 그려야합니다. – petemorris
@middaparka 질문에 답을하고 코멘트에 답을 쓰는 것보다는 간단히 대답하는 것이 어떻겠습니까? – Mecki