Domanda


Ho sottoclassato la classe NSButtonCell per dare un aspetto diverso al mio pulsante. Ho il codice di disegno che funziona bene. È un pulsante arrotondato pieno di cggradients per assomigliare ai controlli di riproduzione di iTunes. Non sono completamente gli stessi, ma assomigliano abbastanza a me.

Ora il mio problema è il tipo di pulsante. Ho impostato il tipo di pulsante in -[PlayerButtonCell initImageCell:] Ma non lo sto facendo funzionare per disegnare l'aspetto spinto solo quando il pulsante viene premuto. Ti presento un pezzo del mio codice:

//
//  PlayerButtonCell.m
//  DownTube
//

#import "PlayerButtonCell.h"

@implementation PlayerButtonCell
/* MARK: Init */
- (id)initImageCell:(NSImage *)image {
    self = [super initImageCell:image];
    if(self != nil) {
        [self setImage:image];
        [self setButtonType:NSMomentaryPushInButton];
    }
    return self;
}

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
    NSImage *myImage;
    NSBezierPath *myPath;
    NSRect myFrame;
    NSInteger myState;

    myFrame = NSInsetRect(cellFrame , STROKE_WIDTH / 2.0 , STROKE_WIDTH / 2.0);
    myImage = [self image];
    myState = [self state];

    NSLog(@"%d", [self buttonType]);

    /* Create bezier path */
    {
        myPath = [NSBezierPath bezierPathWithOvalInRect:myFrame];
    }

    /* Fill with background color */
    {
        /* Fill code here */
    }


    /* Draw gradient if on */
    if(myState == NSOffState) {
        /* Code to draw the button when it's not pushed in */

    } else {
        /* Code to draw the button when it IS pressed */
    }

    /* Stroke */
    {
        /* Code to stroke the bezier path's edge. */
    }
}
@end

Come puoi vedere, controllo lo stato spinto dallo status da [NSButtonCell state] metodo. Ma la cella del pulsante agisce come una casella di controllo, come in NSSwitchButton. Questo, non voglio. Voglio che la luce momentanea.

Spero che qualcuno possa aiutarmi,
ief2

Modifica: creo un pulsante con questo codice è di qualsiasi uso:

- (NSButton *)makeRefreshButton {
    NSButton *myButton;
    NSRect myFrame;
    NSImage *myIcon;
    PlayerButtonCell *myCell;

    myIcon = [NSImage imageNamed:kPlayerViewRefreshIconName];
    myCell = [[PlayerButtonCell alloc] initImageCell:myIcon];

    myFrame.origin = NSMakePoint(CONTENT_PADDING , CONTENT_PADDING);
    myFrame.size = CONTROL_PLAYBACK_SIZE;

    myButton = [[NSButton alloc] initWithFrame:myFrame];
    [myButton setCell:myCell];
    [myButton setButtonType:NSMomentaryPushInButton];

    [myCell release];

    return [myButton autorelease];
}

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top