I would like to display the progress like the image(except the black background that is screen color). I am using progress view for this. Here user doesn't have chance to change the progress manually.
Please help me on this.
This might help someone. I have implemented this behaviour with UISlider instead of UIProgressView. UISlider solves the problem.
UIImage *minImage = [[UIImage imageNamed:#"slider_minimum.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *maxImage = [[UIImage imageNamed:#"slider_maximum.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *thumbImage = [UIImage imageNamed:#"thumb.png"];
[self.uisliderObj setMaximumTrackImage:maxImage
forState:UIControlStateNormal];
[self.uisliderObj setMinimumTrackImage:minImage
forState:UIControlStateNormal];
[self.uisliderObj setThumbImage:thumbImage
forState:UIControlStateNormal];
source is from this link
You will find a lot of simple codes on WWW.COCOACONTROLS.COM . You can check it.
If you want to customise on own you can also subclass UIPROGRESSBAR class
and change the trackImage and progressImage of the UIProgressView.
Related
I'm trying to create a simple circle view.
I did it before, and now for some reason the circle is not precise (image attached).
In my code i'm taking the height of the "sliderPin" view, and the half value of it goes for the cornerRadius of its layer.
I tried to take the constraint height value of the "sliderPin" view as well, but I got the same results.
* The width & height of the view are equal.
My code:
[self.sliderPin.layer setBorderColor:borderColor];
[self.sliderPin.layer setBorderWidth:2];
self.sliderPin.clipsToBounds = YES;
self.sliderPin.layer.masksToBounds = YES;
[setCornerRadius:CGRectGetHeight(self.sliderPin.frame) / 2];
Better to use UISlider, with given methods. It might solve your problem.
UIImage *minImage = [[UIImage imageNamed:#"slider_minimum.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *maxImage = [[UIImage imageNamed:#"slider_maximum.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *thumbImage = [UIImage imageNamed:#"thumb.png"];
[[UISlider appearance] setMaximumTrackImage:maxImage
forState:UIControlStateNormal];
[[UISlider appearance] setMinimumTrackImage:minImage
forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:thumbImage
forState:UIControlStateNormal];
For Height:
You can customise by inheriting UISlider and over-riding method
- (CGRect)trackRectForBounds:(CGRect)bounds {
CGRect rect = CGRectMake(0, 0, 100, 30);//change it to any size you want
return rect;
}
You can customise more by inheriting respective methods.
Thanks.
Make sure constraintsare not conflicting. If you are using auto layout, set sliderPin's width and height equal constraints or aspect ratio 1:1 might solve the problem.
I've subclassed UISlider and increased the width by doing this:
-(CGRect)trackRectForBounds:(CGRect)bounds {
bounds.size.height = 50;
return bounds;
}
And changed the thumb image:
- (void)drawRect:(CGRect)rect {
// Drawing code
[self setThumbImage:[UIImage imageNamed:#"icon_circle"] forState:UIControlStateNormal];
}
But this is happening:
The minimum track image starts from the center. I want to make it start from the thumb end. So initially, till the thumb it should be blue and when I drag it till the end the whole slider should be blue but at the end of the slider, the slider is not curved. It has got sharped edges. What should I do to get this right?
Couldn't find much help so I made my own custom one instead. It's also available on GitHub. https://github.com/bhavukjain1/SlideToActionSlideriOS
Are you setting the following properties?
UIImage *minImage = [[UIImage imageNamed:#"slider_minimum.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *maxImage = [[UIImage imageNamed:#"slider_maximum.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 5)];
UIImage *thumbImage = [UIImage imageNamed:#"sliderhandle.png"];
[[UISlider appearance] setMaximumTrackImage:maxImage forState:UIControlStateNormal];
[[UISlider appearance] setMinimumTrackImage:minImage forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:thumbImage forState:UIControlStateNormal];
}
if so, take a look at this tutorial of how to create a custom slider, it comes with a sample project, may be it's easier for you to find your error by comparing your implementation against a working one.
To solve the rectangular corners issue, in drawRect
self.layer.cornerRadius = 25;
self.clipsToBounds = YES;
To show the correct image while dragging, you need to set this as well:
[self setThumbImage:[UIImage imageNamed:#"icon_circle"] forState:UIControlStateHighlighted];
I am using:
[pageSlider setThumbImage:[UIImage imageNamed:#"UISliderThumb.png"] forState:UIControlStateNormal];
It works alright in iOS6 but for iOS7, the thumb image is under the progress bar, like so:
How do I get the thumb image to appear on the top like it should?
Bump: Anything?
I think you are adding the thumb image first then u are adding minimum and maximum image for slider. You should first add minimum and maximum image for the slider then add Thumb image for the slider, See my below code.
UIImage *trackLeftImage = [[UIImage imageNamed:#"greenvolume-slide.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 14, 0, 14)];
[_globalSlider setMinimumTrackImage:trackLeftImage forState:UIControlStateNormal];
UIImage *trackRightImage = [[UIImage imageNamed:#"volume-slide.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 14, 0, 14)];
[_globalSlider setMaximumTrackImage:trackRightImage forState:UIControlStateNormal];
UIImage *ball = [UIImage imageNamed:#"volume-dragger.png"];
[_globalSlider setThumbImage:ball forState:UIControlStateNormal];
Thanks.
Try the below code can help you :)
[pageSlider setThumbImage:[[UIImage imageNamed:#"UISliderThumb.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
Something weird and frustrating is happening with the UINavigationBar on iOS7. I'm trying to add an image like this:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"Logo_Small.png"] forBarMetrics:UIBarMetricsDefault];
The result is that the lettering of my header -- the Hebrew letters -- repeat all over the navigation bar.
I tried all four options for the UIBarMetrics flag, but with the other three the logo just disappears. I also set the image size to 320x64, as per the documentation. But nothing seems to do the right thing, and I'm on the verge of giving up using a logo and just have a controller.title.
Do the below:
UIImage *gradientImage = [[UIImage imageNamed:#"Logo_Small.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(-4, 300, 10, 300)];// play here
[[UINavigationBar appearance] setBackgroundImage:gradientImage forBarMetrics:UIBarMetricsDefault];
you can do like this
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,44)];
iv.image = [UIImage imageNamed:#"Logo_Small.png"];
self.navigationItem.titleView = iv;
Use this,
UIImage *navBarImage64 = [[UIImage imageNamed:#"Logo_Small.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:navBarImage64 forBarMetrics:UIBarMetricsDefault];
If above is not working then add imageview in your NavigationBar as below code. it work.
UIImage *image = [UIImage imageNamed: #"NavigationBar#2x.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
imageView.frame = CGRectMake(0, 0, 320, 44);
[self.navigationController.navigationBar addSubview:imageView];
You code is actually works. The problem is that you are probably calling it after UINavigationBar was added to screen.
To verify that your code is working you can try to put into AppDelegate's didiFinishedLaunchingWithOptions.
To customize navigation bar with Image use this,
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"ImageName.png"] forBarMetrics:UIBarMetricsDefault];
[slider setMaximumTrackTintColor: color]
has unexpected results in iOS 7.1 (the slider bar changes its position appearing at top instead of vertical center or disappears completely), while working fine with prior versions.
[slider setMinimumTrackTintColor: color]
does render the expected result.
This question might be related: UISlider setMaximumTrackTintColor,
but no answer so far.
Update:
I get this: instead of:
Update #2:
Using setMaximumTrackImage might work, but the solution I'm looking for is a way to set any random color and not a preexisting image.
Update #3:
This issue is still present in iOS 7.1.1.
Found this workaroud:
Create a 1x1px UIImage from a UIColor on the fly:
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
[color setFill];
UIRectFill(rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
and then
[slider setMaximumTrackImage:image forState:UIControlStateNormal];
Looks like an expensive solution but it gets the job done.
Try this out:
UIImage *sliderLeftTrackImage = [[UIImage imageNamed:#"LeftImage.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
UIImage *sliderRightTrackImage = [[UIImage imageNamed:#"RightImage.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[sliderName setMinimumTrackImage: sliderLeftTrackImage forState: UIControlStateNormal];
[sliderName setMaximumTrackImage: sliderRightTrackImage forState: UIControlStateNormal];
If you want to change thumb image the following code will work:
[sliderName setThumbImage:[UIImage imageNamed:#"ThumbImgName.png"] forState:UIControlStateNormal];
[sliderName setThumbImage:[UIImage imageNamed:#"ThumbImgName.png"] forState:UIControlStateHighlighted];
In same way, you can also use color instead of images.
I've created 2px images with the colour of slider track.
And then I set they as tracking images (here's with thumb image for iPad and iPhone)
UIImage *thumbImage = [UIImage imageNamed:#"slider"];
UIImage *trackImage;
if (isiPad) {
[[UISlider appearance] setThumbImage:thumbImage forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:thumbImage forState:UIControlStateHighlighted];
trackImage = [UIImage imageNamed:#"menu-bar-ipad"];
}
else {
[[UISlider appearance] setThumbImage:[self imageWithImage:thumbImage scaledToSize:CGSizeMake(27, 27)] forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:[self imageWithImage:thumbImage scaledToSize:CGSizeMake(27, 27)] forState:UIControlStateHighlighted];
trackImage = [UIImage imageNamed:#"menu-bar"];
}
[[UISlider appearance] setMinimumTrackImage:trackImage forState:UIControlStateNormal];
[[UISlider appearance] setMaximumTrackImage:trackImage forState:UIControlStateNormal];
And that's all. Same solution as msmq I guess. And you can see both ways how to make a large image - two images way and scaling way.
Update
Reported this bug and it's already well known. Hopefully they will fix it soon...
Maybe a little bit late, but - here is the answer
You should read description of setter:
The color used to tint the standard maximum track images. Setting this
property removes any custom maximum track images associated with the
slider.
Also this applicable only for maximum color, because minimum setter just change titntColor:
The color used to tint the standard minimum track images.
This mean that slider use some image for maximum track and if u just set tint color nothing will be changes (nothing can't be tinted).
Solution (thanks to #user623396):
UIImage *currentSliderMaximumImage = self.slider.currentMaximumTrackImage;
CGRect rect = CGRectMake(0, 0, currentSliderMaximumImage.size.width, currentSliderMaximumImage.size.height);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
[[[DynamicUIService service] currentApplicationColor] setFill];
UIRectFill(rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self.slider setMaximumTrackImage:image forState:UIControlStateNormal];
As result u will get