내 프로젝트에서 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
및 구현 .
나는 이것이 일종의 고통이라는 것을 알고 있지만, nsslider를 서브 클래스 화하고 drawRect를 재정의해야합니다. 슬라이더 손잡이 셀에 적절한 메시지를 보내 올바른 위치에 그림을 그려야합니다. 더 쉬운 방법으로, 나는 내일 몇 가지 예를 살펴볼 것이다. –