UIProgressView custom track and progress images in iOS 7.1
This is very annoying. I didn't find a way to fix this without subclassing UIProgressView
.
Anyway here's how I fixed this: https://gist.github.com/JohnEstropia/9482567
You will have to change occurrences of UIProgressView
to JEProgressView
, including those in NIBs and storyboards.
Basically, you'd need to force assigning the images directly to the UIProgressView
's children UIImageView
s.
The subclass is needed to override layoutSubviews
, where you adjust the heights of the imageViews according to the image sizes.
UIProgressView custom images doesn't work in iOS 7.1
Okay I have worked it out. I know it must be very basic Xcode stuff - but if there is others who have the same issue as I had, here is what I did.
- Download the JEProgressView files from github. (https://gist.github.com/JohnEstropia/9482567)
- Import them into the project.
- In the storyboard (if you use that) select the current ProgressView, and in the right side of the screen under 'Identity inspector', in the field 'Class' enter : "JEProgressView"
Maybe it is placed a little different on the screen, and you have to adjust a little afterwards in the x and y frame settings. But after these steps it should work!
Pretty simple, but for a beginner like me it took some time to figure out :-P Hopefully this can save some time for other beginners ;-)
UIProgressView track and progress images not working in iOS7
Found a solution. If anyone else is stuck on this check out this answer and suggested code to workaround the issue: UIProgressView custom track and progress images in iOS 7.1
UIProgressView is not displaying custom track image
This is broken in iOS 7.1. There is a radar open on this: http://www.openradar.me/16113307
I wrote a drop-in replacement for UIProgressView
that supports custom images. You can get it as part of RZUtils (look for RZProgressView
).
UIProgressView and Custom Track and Progress Images (iOS 5 properties)
Here's what's going on:
The images you provide to the UIProgressView
are basically being shoved in to UIImageViews
, and the UIImageView
is stretching the image to fill the space.
If you simply do:
[progressView setTrackImage:[UIImage imageNamed:@"track.png"]];
Then you're going to get weird results, because it's trying to stretch a 10px wide image to fill (for example) a 100px wide image view. This means (roughly) that every pixel in the image will be repeated 10 times. So if the pixels in our image were:
0123456789
Then putting that image straight into a 100px wide image view would stretch it something like this:
000000000011111111112222222222333333333344444444445555555555...
This is what's happening to you.
What you really want to have happen is this:
01234567812345678123456781234567812345678...123456789
In other words, you want the image to have a 1 point left edge that is never stretched, the center to be tiled, and to have a 1 point right edge that is also never stretched. To do this, you'll need to make the image resizable:
UIImage *track = [[UIImage imageNamed:@"track"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 1, 0, 1)];
[progressView setTrackImage:track];
If you want this to tile appropriately vertically as well, then the edge insets should be {1, 1, 1, 1}
(assuming you want a 1 point border).
Do the same to the progressImage
, and you'll end up with something that looks correct:
tl;dr:
Your images need to be resizable.
customize progressview / UISlider in ios
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
increase UIProgressView height when using it as titleView in navigation bar
I solved this in a peculiarly tricky way. We already know that providing a height constraint should work. But simply doing that crashed my app. In the end I had a brainstorm. I used another view as my titleView
, and put the progress view inside of that. Now I was able to apply appropriate constraints:
UIProgressView* prog = [[UIProgressView alloc] init];
self.prog = prog;
self.prog.progressTintColor = [UIColor colorWithRed:1.000 green:0.869 blue:0.275 alpha:1.000];
self.prog.trackTintColor = [UIColor darkGrayColor];
self.prog.translatesAutoresizingMaskIntoConstraints = NO;
CGFloat w = 150;
CGFloat h = 10;
[self.prog addConstraint:[NSLayoutConstraint constraintWithItem:self.prog attribute:NSLayoutAttributeWidth relatedBy:0 toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:w]];
[self.prog addConstraint:[NSLayoutConstraint constraintWithItem:self.prog attribute:NSLayoutAttributeHeight relatedBy:0 toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:h]];
UIView* v = [[UIView alloc] initWithFrame:CGRectMake(0,0,w,h)];
[v addSubview:self.prog];
[v addConstraint:[NSLayoutConstraint constraintWithItem:self.prog attribute:NSLayoutAttributeCenterX relatedBy:0 toItem:v attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
[v addConstraint:[NSLayoutConstraint constraintWithItem:self.prog attribute:NSLayoutAttributeCenterY relatedBy:0 toItem:v attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
v.clipsToBounds = YES;
v.layer.cornerRadius = 4;
self.navigationItem.titleView = v;
As you can see, I also took advantage of this to add some rounding to the corners. I think the result is quite nice-looking.
UIProgressView progress value rounds
Use
cell.attendanceProgress.frame=CGRectMake(0,0,cell.attendanceProgress.frame.size.width, cell.frame.size.height);
CATransform3D transform = CATransform3DScale(cell.attendanceProgress.layer.transform, 1.0f,cell.frame.size.height, 1.0f);
cell.attendanceProgress.layer.transform = transform;
Make sure set frame before transform.
Related Topics
Bundle.Main.Path(Forresource:Oftype:Indirectory:) Returns Nil
Xcode Exception Breakpoint Doesn't Print Details of the Exception Being Thrown
What Is a Provisioning Profile Used for When Developing iPhone Applications
Keeping the Contentoffset in a Uicollectionview While Rotating Interface Orientation
Face Recognition on the Iphone
Pods-Resources.Sh Permission Denied in iOS Project
How to Develop iPhone Mdm Server
Dial a Phone Number with an Access Code Programmatically in iOS
iOS Builds/Ipa Creation No Longer Works from the Command Line
Dismissing Uialertviews When Entering Background State
iOS Horizontal Slideview with Vertical Menu
Change Frame Programmatically with Auto Layout
Change Push Notification Sound
Where and When to Get Data for Watch Complication
Uitableviewrowaction Image for Title
Radial Gradient Background in Swift
Want to Create a Cool Static UI But:"Static Table Views Are Only Valid..."