Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save IliaIdakiev/6032313 to your computer and use it in GitHub Desktop.
Save IliaIdakiev/6032313 to your computer and use it in GitHub Desktop.
Cocoa
#import <Cocoa/Cocoa.h>
@interface FMICustomSlider : NSView
{
NSGradient* gradient;
CGFloat angle;
}
@property (nonatomic) NSGradient* gradient;
@property (nonatomic) CGFloat angle;
@end
#import "FMICustomSlider.h"
@implementation FMICustomSlider
@synthesize gradient;
@synthesize angle;
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame: frame];
if (self) {
self.gradient = [[NSGradient alloc] initWithStartingColor: [NSColor whiteColor] endingColor: [NSColor grayColor]];
self.angle = 270;
self.wantsLayer = YES;
self.layer.masksToBounds = YES;
self.layer.cornerRadius = 5.0;
NSView *imView = [[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 50, 50)];
// imView.layer.backgroundColor = (__bridge CGColorRef)([NSColor purpleColor]);
//NSImage *myImage = [[NSImage alloc] initByReferencingFile:@"knob.png"];
//[imView setImage:myImage];
[self addSubview:imView];
}
return self;
}
- (void)drawRect: (NSRect)dirtyRect
{
if (self.gradient) {
[self.gradient drawInRect: [self bounds] angle: self.angle];
NSRect imageRect, controlRect;
NSImage *myImage = [[NSImage alloc] initByReferencingFile:@"knob.png"];
imageRect.origin.x = 0.0;
imageRect.origin.y = 0.0;
imageRect.size = [myImage size];
controlRect = [self bounds];
// [myImage drawInRect:imageRect
// fromRect:controlRect
// operation:NSCompositeCopy
// fraction:1.0];
//[myImage drawInRect:imageRect fromRect:dirtyRect operation:NSCompositeCopy fraction:1.0];
}
else {
NSLog(@"No gradient set up for ACTGradientView: %@", self);
}
}
-(void)setGradient:(NSGradient*)gr
{
if (![self.gradient isEqualTo: gr]) {
gradient = gr;
[self setNeedsDisplay: TRUE];
}
}
-(void)setAngle:(CGFloat)an
{
angle = an;
[self setNeedsDisplay: TRUE];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment