質問

does anyone know if you can remove the edge of the UIStepper of Ios7? I wish you could see only the decrease and the increase without a border around ... E 'possible to make a custom?

thanks to all

役に立ちましたか?

解決 4

It's not possible to customise the UIStepper. You can only change the background image, the tintColor, and the two images (plus and minus). I think the best and easy way is to create your own like this. 1) Create two buttons and put as text + and - 2) This is the starting code. Then you need to handle the maximum and minimum values:

.h file

 @interface ViewController : UIViewController {
    NSInteger value;
}

- (IBAction)plus:(id)sender;
- (IBAction)minus:(id)sender;


.m file


- (IBAction)plus:(id)sender {
    value++;
}

- (IBAction)minus:(id)sender {
    --value;
}

他のヒント

If you have a custom image for the increment and decrement buttons you can use this solution. Make the tintColor property of the stepper [UIColor clearColor]. That way the border and the buttons will be invisible. To prevent the buttons being invisible, do this:

UIImage *incrementImageFromFile = [UIImage imageNamed:@"theName"];
UIImage *incrementImage = [incrementImageFromFile imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

You also need to make your images the same tint color as you would like to use.

Actually yes, you can set the background image to a pure color image, like this:

- (UIImage *)emptyImageForSteper
{
    UIGraphicsBeginImageContext(CGSizeMake(1, 1));
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, COLOR_BUTTON_LIGHT.CGColor);
    CGContextFillRect(context, CGRectMake(0, 0, 1, 1));
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

[steper setBackgroundImage:self.emptyImageForSteper forState:UIControlStateNormal];

there you go

It works,for Swift coders:

    var incrementImageFromFile : UIImage = UIImage(named: "Offer_Plus")!
    var incrementImage : UIImage = incrementImageFromFile.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

    var decrementImageFromFile : UIImage = UIImage(named: "Offer_Minus")!
    var decrementImage : UIImage = decrementImageFromFile.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

    self.seatStepper.tintColor = UIColor.clearColor()
    self.seatStepper.setDecrementImage(decrementImage, forState:  UIControlState.Normal)
    self.seatStepper.setIncrementImage(incrementImage, forState:  UIControlState.Normal)

OutPut is:

enter image description here

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top