CAShapeLayer
에서 나는 UIBezierPath
을 닫았습니다. fillColor
을 설정하여이 도형을 채울 수 있지만 그래디언트로 도형을 채우고 싶습니다. CAGradientLayer
을 설정하여 베 지어 경로로 윤곽선이 표시된 모양으로자를 수 있습니까?iOS에서 그라데이션을 사용하여 경로 채우기
8
A
답변
5
원하는 것은 마스크입니다.
[gradientLayer setMask:shapeLayer];
19
이 초안의 예는 다음과 같습니다 : CAGradientlayer 지금처럼 모양의 경계에 클립 수있는 -setMask 방법이
...
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *gradientColor = [UIColor colorWithRed:0.51 green:0.0 blue:0.49 alpha:1.0];
NSArray *gradientColors = [NSArray arrayWithObjects:
(id)[UIColor blueColor].CGColor,
(id)gradientColor.CGColor,
(id)[UIColor redColor].CGColor, nil];
CGFloat gradientLocations[] = {0, 0.5, 1};
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)gradientColors, gradientLocations);
UIBezierPath *roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(10, 10, 200, 200) cornerRadius:6];
CGContextSaveGState(context);
[roundedRectanglePath fill];
[roundedRectanglePath addClip];
CGContextDrawLinearGradient(context, gradient, CGPointMake(10, 10), CGPointMake(210, 10), 0);
CGColorSpaceRelease(colorSpace);
CGGradientRelease(gradient);
...
관련 문제
- 1. 경로 채우기 애니메이션 - Silverlight
- 2. CSS3 그라데이션을 SVG로
- 3. iOS에서 내 문서 폴더의 경로 찾기
- 4. 이미지 경로 열의 이미지로 datagridview 열 채우기
- 5. 경로 채우기 속성이 비정상적인 동작을 바인딩합니까?
- 6. JSON 파일의 기본 방법은 일반 JS를 사용하여 자주 그라데이션을 적용합니다.
- 7. C#에서 LinearGradientBrush를 사용하여 정확한 그라데이션을 페인트하는 방법은 무엇입니까?
- 8. NSKeyedArchiver를 사용하여 iOS에서 보관
- 9. iOS에서 tick() 함수를 사용하여
- 10. iOS에서 LDAP를 사용하여 인증하기
- 11. JSON 데이터 가져 오기 및 iOS에서 TableView 채우기
- 12. PHP + Imagick : 이미지의 일부분에 그라데이션을 적용하는 법?
- 13. div에서 그라데이션을 희미하게 할 수 있습니까?
- 14. Android에서 액세스 색상 및 그라데이션을 사용하려면 어떻게해야합니까?
- 15. 텍스트 색상에 그라데이션을 설정할 수 있습니까?
- 16. contourf, colormap, matlab에서 그라데이션을 만드는 colorbar
- 17. Graphics2D를 사용하여 투명도로 채우기
- 18. TreeMap을 사용하여 ComboBox 채우기
- 19. 개체를 사용하여 셀셋 채우기
- 20. moq을 사용하여 httpcontext.request 채우기
- 21. 반복자를 사용하여 컬렉션 채우기
- 22. irb를 사용하여 데이터베이스 채우기
- 23. 람다를 사용하여 DataGridView 채우기
- 24. 양식을 사용하여 링크 채우기
- 25. LINQ to SQL을 사용하여 이미지 채우기
- 26. "채우기"채우기
- 27. iOS에서 블록을 사용하여 전환 전환
- 28. RestKit을 사용하여 iOS에서 WCF로 게시
- 29. iOS에서 JSON을 사용하여 데이터 수신
- 30. coreplot을 사용하여 ios에서 CPTXYPlotSpace를 번역합니다.
이것은 좋은입니다,하지만 당신은해야 그라데이션 및 색상 공간을 해제합니다. – Sulthan
덕분에, 나는 원래의 게시물이 마스크 기능을하기 때문에 그들에게 – WhiteTiger
을 넣어 잊었, 나는 또한 추가 한 다음 'CGContextAddPath (문맥, roundedRectanglePath.CGPath)' 'CGContextClip (컨텍스트)' CGContextDrawLinearGradient''전 – maggix