C4 stepper custom images - ios

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:
Strangely, what appears on the canvas looks something like this: !
Are there any special requirements for the zoomStepperImages? A certain size or something?

There are special requirements.
The background image used is "stretchable", so you have to design a button image that can be stretched if needed. If you have a look at any of the button images (incl. in the Media.xcassets folder) you'll see that they are generic. For example, the selected button background image looks like:
Similarly, the increment / decrement images are themselves independent of the background images. The incrementNormal image included in the same folder looks like:
You can see how the default values of the C4Stepper class are initialized in C4AppDelegate.m:
...
[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];
So, what you want to do is create an image for your background (mine is stretchable because the stuff in the middle are straight lines that can be stretched horizontally without looking stretched. You also want to create independent + - images for increment / decrement sides of the button.
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.

Related

How to create a scrolling image gallery in iOS?

In my app, I have 5 images, and 2 buttons(next and previous).
I have stored those images in an array.
When next button is pressed, I want to remove the current image and display the next image, and for previous button, it is vice versa.
I have done this using the code.
-(void)nextButton:(id)sender
{
if (i < (array.count-1))
{
i=i+1;
imageView.image = [images objectAtIndex:i];
}
}
-(void)previousButton:(id)sender
{
if(i >= 1)
{
i=i-1;
imageView.image=[images objectAtIndex:i];
}
}
Now, my doubt is, when the image changes, there happens no animation, simple the next image replaces the previous image.
But, my request is when I click the button, the previous button should decrease by the width and move out of the imageView and the next image should come inside the imageView gradually like this
I understand it and it looks like you would need some custom animation, check out it has various animation and u can use anyone you like
Currently you are just simply assigning image to the imageview. that's why there is no animation. For this animation, you can use the below library
http://code4app.net/ios/iCarousel-for-Cover-Flow/4f87d2db06f6e79d32000000
I guess you need a cover flow effect. Try browsing iCarousel. Try link below, it provides great options for different style
https://www.cocoacontrols.com/controls/icarousel
use iCarousel .. in this you will have # 7 types of animation. if you don't want to use 3rd party code. Better option is fade-out current image and fade-in new image.

How to make UISlider thicker when it is first displayed?

I am trying to make a UISlider that has a fat track. I tried this, and it almost works. However, when the UISlider is first displayed, the track bar is normal. Only when it gets a touch event does it get thicker.
Here is the code I added to my subclass of UISlider, as recommended:
- (CGRect)trackRectForBounds:(CGRect)bounds
{
return bounds;
}
I don't understand how this works, so I can't figure out why it isn't working perfectly. Here are my questions:
How does this work?
How can I control how thick it makes the track?
How can I make it affect the track when the UISlider is first drawn?
Of course, the third question is the most important, though the others will help me in my understanding.
One other thing to consider: when it is first displayed, I hide the thumb:
[slider setThumbImage:[[UIImage alloc] init] forState:UIControlStateNormal];
When the user touches the slider, I display the thumb like this:
[slider setThumbImage:nil forState:UIControlStateNormal];
I mention this because I wonder if that is somehow interfering with the trackRectForBounds magic.
Thanks!
Question 1. From the docs:
If you want to customize the track rectangle, you can override this
method and return a different rectangle. The returned rectangle is
used to scale the track and thumb images during drawing.
The default implementation of this method returns a smaller rectangle than the one it is passed. Yours simply returns what it's passed, instead of shrinking it first.
Question 2. Return a larger or smaller CGRect, for example:
return CGRectMake(0, 0, 500, 200);
Question 3. I think the method only gets called if you don't set a custom image, which is why it has no effect until you set the image to nil. If you want to override the image, try overriding the slider images with actual images that look the way you want.

ios custom progress bar designing

I want to create a custom progress bar for my app. I am new to iOS development and finding it difficult to understand codes on google which confuse me a lot. What I want is like growing animated progress bar.
e.g: like showing progress in terms of a tree growth from small plant(to a complete tree) which denotes the process completion.
Where and how to start? And also is Core Graphics or cocos2d which one will be apt for this?
If you're doing something graphical like a tree growing, do you already have the animation you want to use as a series of images?
If so, you could use a UIImageView. Whenever you want to update your progress bar, just check the progress of your task, and use that to work out which number image to display. So if you had twelve images, you could find the percentage complete of your task, divide by 100 then multiply by twelve (and then convert to an int) to get the image number you want.
Once you've done that, just get the appropriately named image and put it in your image view:
self.myImageView.image = [UIImage imageNamed:[NSString stringWithFormat:#"frame-%i", myImageNumber]];
As for when to do the progress check, that depends on the task you are doing. Some tasks have a natural place to inject a callback to update the UI, and for others it's better to just use a timer.
you cannot change much in uiprogressbar instead you can use UISlide to behave like progressbar
.
you can only change the frame of progressbar as:-
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle
:UIProgressViewStyleBar];
[progressView setFrame:CGRectMake(0,0,320,10)];
you can create a uiSlider and make its ThumbImage to nil,setMinimumTrackImage ans maxtrackImage and then use the custom function on it to show the progress
custom UISlider
https://github.com/jdg/MBProgressHUD
Try this code its modst widely used open source code for your kind of purpose

how to add the dimmed background found in UIAlertView

Im making a custom dialog thats similar to UIAlertView, and was wondering if anyone had any ideas how I can emulate the dimming background as in the photo below.
I agree that you should be very careful to have a real justification for redoing something that is already there, but if you really need it, it's easy:
Create a PNG image with the same size as the targeted device's screen, with alpha. TFill the image black, and add a radial opacity gradient, so that in the center, it is relatively transparent, while towards the screen edges it'll be more opqaue. This effect is called vignetting. Maybe there even is a vignetting filter on your preferred image editor, which you could use on a completely transparent image.
This image approach also has the benefit of allowing you to use completely different effects of fading away the background.
Create a UIImageView with the vignette image, and transparent background. Add the view to your app's Window, on top of all other views, but below your alertView:
UIImageView *vignetteView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:#"vignette.png"]];
vignetteView.backgroundColor = [UIColor clearColor];
vignetteView.userInteractionEnabled = YES; //this means users won't be able to touch the UI elements below
[self.view.window insertSubview: vignetteView belowSubview: myAlertView];
First off, I'd recommend that you do your best to avoid the need for a custom modal dialog. You can usually give your feedback contextually within the flow of your application's actual views.
If your app targets iOS 5 only, UIAlertView offers three new styles to allow text input, secure text input, or a user name and password combo.
If you still need a custom modal alert, and you're looking to stay consistent with the iOS look and feel, and maintain resolution independence, I'd recommend that you avoid using static graphical assets. Instead, take the (somewhat hackish) approach of subclassing UIAlertView, and adding your own controls to it. You can find examples of doing this here and here.

Disable whole UIView

My app needs to save an image to disk. I do this in a separate thread, so the UI is still responsive, BUT, I do not want the user to add a new image until the first one is saved (about 1 second.)
At the moment, I'm disabling the 'take another picture' button and greying it out, but I'm wondering if there is a method that will disable the whole view, greying out the buttons and darkening the background, like what happens when a UIActionSheet is presented.
I've looked through the UIView docs and don't see anything like this, but it seems like such a useful pattern that is frequently used by Apple that I figured I'd ask, just in case there was such a thing.
Obviously I could do it manually, but why reinvent the wheel if its already part of the API.
TIA: John
set whatever view (main view, subview, etc.) you want to appear disabled to
view.userInteractionEnabled = NO
and also
view.alpha = 0.3f
and maybe even
view.backgroundColor = [UIColor grayColor]
to boot. These last two can be animated, b.t.w.
Present another view with the shadow and the gradient etcetera over this view thus giving it an effect of graying out with shadows. You may even create an image if you know your photoshop. Just show that image on a UIImageView over this view to be blocked. Give the image some nice translucency, shadows etc etc

Resources