내 프로젝트에서 NSSlider는 AVPlayer의 볼륨을 제어합니다. NSSlider의 왼쪽 부분을 색칠하고 싶습니다. 어떻게이 일을 성취 할 수 있습니까?NSSlider에서 노브 왼쪽 부분의 색상을 지정하는 방법
1
A
답변
1
이 경우 NSProgressIndicator
을 사용해야합니다.
사용자 지정 NSSliderCell을 사용하고 - (BOOL)_usesCustomTrackImage
을 재정 의하여 YES
을 반환하고 - (void)drawBarInside:(NSRect)cellFrame flipped:(BOOL)flipped
을 재정 의하여 사용자 지정 막대를 그릴 수 있습니다. 여기서 [NSCell doubleValue]를 사용하여 슬라이더의 현재 위치를 가져올 수 있습니다.
0
당신은 NSSliderCell의 하위 클래스와 같은 것을 작성해야 : 당신이 정말 간단하고 빨리 원하는 것을 만들 에 당신을 도울 것입니다 내가 LADSLider을 만든
- (void)drawKnob:(NSRect)knobRect {
[super drawKnob:knobRect];
_currentKnobRect = knobRect;
}
-(void)drawBarInside:(NSRect)cellFrame flipped:(BOOL)flipped {
_barRect = cellFrame;
NSRect beforeKnobRect = [self createBeforeKnobRect];
NSRect afterKnobRect = [self createAfterKnobRect];
// Draw bar before the knob
NSDrawThreePartImage(beforeKnobRect, _barLeftAgeImage, _barFillBeforeKnobImage, _barFillBeforeKnobImage,
NO, NSCompositeSourceOver, 1.0, flipped);
// If you want to draw the default background
// add the following line at the at the beginning of the method:
// [super drawBarInside:cellFrame flipped:flipped];
// And comment the next line:
NSDrawThreePartImage(afterKnobRect, _barFillImage, _barFillImage, _barRightAgeImage,
NO, NSCompositeSourceOver, 1.0, flipped);
}
- (NSRect)createBeforeKnobRect {
NSRect beforeKnobRect = _barRect;
beforeKnobRect.size.width = _currentKnobRect.origin.x + _knobImage.size.width/2;
beforeKnobRect.size.height = _barFillBeforeKnobImage.size.height;
beforeKnobRect.origin.y = beforeKnobRect.size.height/2;
return beforeKnobRect;
}
- (NSRect)createAfterKnobRect {
NSRect afterKnobRect = _currentKnobRect;
afterKnobRect.origin.x += _knobImage.size.width/2;
afterKnobRect.size.width = _barRect.size.width - afterKnobRect.origin.x;
afterKnobRect.size.height = _barFillImage.size.height;
afterKnobRect.origin.y = afterKnobRect.size.height/2;
return afterKnobRect;
}
:
@interface CustomSliderCell : NSSliderCell {
NSRect _barRect;
NSRect _currentKnobRect;
}
// You should set image for the barFill
// (or not if you want to use the default background)
// And image for the bar before the knob image
@property (strong, nonatomic) NSImage *barFillImage;
@property (strong, nonatomic) NSImage *barFillBeforeKnobImage;
// Slider also has the ages so you should set
// the different images for the left and the right one:
@property (strong, nonatomic) NSImage *barLeftAgeImage;
@property (strong, nonatomic) NSImage *barRightAgeImage;
@end
및 구현 .
관련 문제
- 1. 번호 색상을 지정하는 방법
- 2. 메시지 텍스트에 둘 이상의 색상을 지정하는 방법
- 3. Netbeans에서 .htaccess 파일의 색상을 지정하는 방법
- 4. JTable에서 특정 행의 색상을 지정하는 방법
- 5. 호버 효과에 임의로 색상을 지정하는 방법
- 6. 이미지의 색상을 지정하는 방법은 무엇입니까?
- 7. HTMLTable에서 특정 셀의 색상을 지정하는 방법은 무엇입니까?
- 8. ios sdk에서 반원형 노브 만들기
- 9. PHP에서 짝수/홀수 표 행의 색상을 지정하는 방법
- 10. Windows Forms에서 텍스트 상자 그라디언트 색상을 지정하는 방법 C#
- 11. matlab 줄거리에서 mutliple 줄에 대한 색상을 지정하는 방법?
- 12. wxPython - 상태 표시 줄의 텍스트 색상을 지정하는 방법
- 13. 색상을 지정하는 방법 Telerik Kendo UI 원형 차트 쐐기?
- 14. XIB에서 왼쪽, 오른쪽 또는 제목보기 단추를 지정하는 방법
- 15. 왼쪽 조인, 오른쪽에서 1 개의 결과를 지정하는 방법?
- 16. IE8 브라우저에 그라디언트 색상을 지정하는 방법은 무엇입니까?
- 17. 자리 표시 자 색상을 지정하는 방법은 무엇입니까?
- 18. mozilla에서 스크롤 막대의 색상을 지정하는 방법은 무엇입니까?
- 19. Java에서 BufferedImage/Image의 색상을 지정하는 방법은 무엇입니까?
- 20. xna에서 C#으로 색상을 지정하는 방법은 무엇입니까?
- 21. WPF DataGrid에 스트라이프 색상을 지정하는 방법은 무엇입니까?
- 22. JComboBox의 항목에 다른 색상을 지정하는 방법은 무엇입니까?
- 23. 드롭 다운에서 단어의 색상을 지정하는 방법은 무엇입니까?
- 24. -webkit-transform에 색상을 지정하는 방법은 무엇입니까?
- 25. Arel과 왼쪽 가입하는 방법?
- 26. EF에서 왼쪽 결합을 지정하는 방법은 무엇입니까?
- 27. 헤드 부분의 내용을 확인하는 방법
- 28. JODReports를 사용하여 데이터에 따라 표 행의 색상을 지정하는 방법은 무엇입니까?
- 29. 안드로이드의 java 코드에서 문자열에 색상을 지정하는 방법은 무엇입니까?
- 30. iOS에서 PDF로 렌더링되는 텍스트의 색상을 지정하는 방법은 무엇입니까?
나는 이것이 일종의 고통이라는 것을 알고 있지만, nsslider를 서브 클래스 화하고 drawRect를 재정의해야합니다. 슬라이더 손잡이 셀에 적절한 메시지를 보내 올바른 위치에 그림을 그려야합니다. 더 쉬운 방법으로, 나는 내일 몇 가지 예를 살펴볼 것이다. –