핵심 그래픽에서 크롬 텍스트 효과를 생성하려고하는데 제대로 보이게하는 데 어려움을 겪고 있습니다. 당신은 그라데이션 가장자리를 볼 수 있듯이선형 그라디언트가 적용된 Chrome 텍스트 효과가 들쭉날쭉 한 가장자리를 나타냄
는상당히입니다 :
이 나는 그럭저럭 한 것입니다 :
이
내가 달성하기 위해 애 쓰고 효과 들쭉날쭉 한. 텍스쳐 채우기를위한 정적 png에 의지하지 않고이 효과를 얻을 수있는 방법이 있습니까? lefteris에 의해 제안을- (void)setGradientFill:(UILabel*)label
{
CGSize textSize = [label.text sizeWithFont:label.font];
CGFloat width = textSize.width; // max 1024 due to Core Graphics limitations
CGFloat height = textSize.height; // max 1024 due to Core Graphics limitations
// create a new bitmap image context
UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), YES, 0.0);
// get context
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetAllowsAntialiasing(context, true);
CGContextSetShouldAntialias(context, true);
// push context to make it current (need to do this manually because we are not drawing in a UIView)
UIGraphicsPushContext(context);
CGContextSetAllowsAntialiasing(context, YES);
CGContextSetShouldAntialias(context, YES);
//draw gradient
CGGradientRef glossGradient;
CGColorSpaceRef rgbColorspace;
size_t num_locations = 5;
CGFloat locations[5] = { 0.0, 0.5, 0.5, 0.65, 1};
CGFloat components[20] = {
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
0.878, 0.878, 0.878, 0.878,
0.78, 0.78, 0.78, 1.0,
1, 1, 1, 1.0
};
rgbColorspace = CGColorSpaceCreateDeviceRGB();
glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);
CGPoint start = CGPointMake(0, 0);
CGPoint end = CGPointMake(width/4, height*1.2);
CGContextDrawLinearGradient(context, glossGradient, start, end, kCGGradientDrawsAfterEndLocation);
CGGradientRelease(glossGradient);
CGColorSpaceRelease(rgbColorspace);
// pop context
UIGraphicsPopContext();
// get a UIImage from the image context
UIImage *gradientImage = UIGraphicsGetImageFromCurrentImageContext();
// clean up drawing environment
UIGraphicsEndImageContext();
label.textColor = [UIColor colorWithPatternImage:gradientImage];
}
편집 :
내가 (아래 왼쪽 이미지) 당신이 만든 확장을 시도
이는 내 코드입니다. 어떤 이유로 가장자리 주위에 인공물이있는 매우 흐린 텍스트가 나타납니다.
_test.frame = CGRectMake(_test.frame.origin.x, _test.frame.origin.y, image.size.width, image.size.height);
_test.image = image;
편집 가장 가까운 솔루션 : lefteris에 의해
솔루션, 당신이 할 수있는 가장 가까운 '
나는 스트레칭 컨텐츠를 피하기 위해 이미지에있는 UIImage 프레임 크기를 조정하고 그래도 지루한 그라디언트 가장자리를 피할 수는 없습니다. 만약 텍스쳐에 Photoshop에서 생성 된 정적 PNG를 사용할 수는 있지만 텍스쳐는 크기에 따라 적용되므로 각 화면에 올바른 효과를 얻기 위해서는 여러 가지 버전이 필요할 수 있습니다. 포함 된 텍스트가 아닌 프레임의 그것을 동적으로하는 것은 가능하지만 제한적입니다.
'UIGraphicsPushContext'를 호출 할 필요가 없습니다. 당신이 그것을 어디에서 얻었는지보세요 : 그것은 이미 * 현재였습니다. –
실제로 이것이 없으면 작동하지 않습니다. – Imran
해당 팝을 제거하는 것을 잊어 버렸기 때문에 작동하지 않았지만 맞았습니다. – Imran