iosc4

C4 stepper custom images


I'm trying to use my own images on a C4Stepper. I'm setting it up like this

@implementation C4WorkSpace{
    C4Stepper *theStepper;
    C4Image *stepperBackground;
    C4Image *stepperPlus;
}

-(void)setup {
    //load backgroundimage
    stepperBackground=[C4Image imageNamed:@"icon_zoom.png"];
    stepperBackground.width=100;

    //load incrementImage
    stepperPlus=[C4Image imageNamed:@"icon_zoom_plus.png"];
    stepperPlus.width=stepperBackground.width/2;

    //setup stepper
    theStepper=[C4Stepper stepper];
    [theStepper setBackgroundImage:stepperBackground forState:NORMAL];
    [theStepper setIncrementImage:stepperPlus forState:NORMAL];

    theStepper.center=self.canvas.center;
    [self.canvas addSubview:theStepper];  
}

The 2 icons look like this:icon_zoom_Plus.pngicon_zoom.png Strangely, what appears on the canvas looks something like this: !screenshot Are there any special requirements for the zoomStepperImages? A certain size or something?


Solution

  • There are special requirements.

    enter image description here

    enter image description here

    ...

    [C4Stepper defaultStyle].style = basicStyle;
    [C4Stepper defaultStyle].tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"lightGrayPattern"]];
    [[C4Stepper defaultStyle] setDecrementImage:[C4Image imageNamed:@"decrementDisabled"] forState:DISABLED];
    [[C4Stepper defaultStyle] setDecrementImage:[C4Image imageNamed:@"decrementNormal"] forState:NORMAL];
    [[C4Stepper defaultStyle] setIncrementImage:[C4Image imageNamed:@"incrementDisabled"] forState:DISABLED];
    [[C4Stepper defaultStyle] setIncrementImage:[C4Image imageNamed:@"incrementNormal"] forState:NORMAL];
    

    Just as a note, when I was creating the C4Button class, I had to play around with the various images I was creating to get them to "look" right... In the end, I had to do a lot of tweaking and experimenting to learn how they were rendered. The difficulty I had in figuring this out was that the rendering mechanism of UIButton itself was a bit strange and I had to learn how to fit things into the button so that they rendered properly.