33

I want to increase the height of progress view in iOS 6 and below i am doing this using appearence method

  UIImage *progressImage = [[UIImage imageNamed:@"sliderbk-progress.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 5)];
[[UIProgressView appearance] setProgressImage:progressImage];

but now in iOS7 this code is not working i even try given below code but no use. Any help will be helpfull. Thanks

[[UIProgressView appearance] setFrame:CGRectMake(20, 100, 280, 100)];
Iqbal Khan
  • 4,587
  • 8
  • 44
  • 83
  • 5
    @Puneet NDA has nothing to do with stackoverflow. There is nothing in the question that is under NDA, by the way. – Sulthan Sep 10 '13 at 11:38
  • @Puneet That's true, however NDA is not enforced on SO (see meta for relevant discussion). Beta can make questions "too localized" (again, see meta). In this case, the question contains nothing protected by NDA (the API is the same) and the question can be safely answered from iOS 6 experience and without breaking NDA. Downvoting or closing question only because it contains words "iOS 7" is stupid. – Sulthan Sep 10 '13 at 12:05
  • 1
    Fair point @Sulthan but the question itself says the code is working in iOS6 and not in iOS7 and the code to set progress image through appearance does work in iOS6. I have not written NDA only because I saw iOS7 in it. – Puneet Sharma Sep 10 '13 at 12:14
  • How do you initialize UIProgressView? – Bms270 Sep 25 '13 at 18:18

7 Answers7

60

If I am understanding the question correctly it sounds like you want to increase the height of the progress view in iOS7, and the code you used previously in iOS6 is no longer working.

I had to solve a similar problem recently and I did this by adding a constraint to the progress view in Interface Builder and setting the height explicitly through the constraint. This solution will require the use of Auto-Layout, so be sure that you have that turned on.

height attribute

Shown: the "Height" attribute on the Size Inspector is visibly greyed out for a Progress View and cannot be changed - however I've defined a constraint on the Progress View itself and set the constraint's height to 50 points, which is actually reflected in IB.

From what I've seen iOS6 Progress Bars have a static height value, so if you also want to support iOS6 then another approach will be necessary for that.

Shog9
  • 156,901
  • 35
  • 231
  • 235
Derek Lee
  • 3,452
  • 3
  • 30
  • 39
  • can we add this from code when it is app is running on iOS7 and in inteface builder by unchecking the autolayout so that it can also work on ios5 – Iqbal Khan Nov 06 '13 at 11:31
  • I set both progress image and tracking image. But as soon as I set tracking image on storyboard, the storyboard looks fine but it goes wrong under the simulator. I have to manually set it in code to get it right. Progress view style also has to be UIProgressViewStyleBar. – huggie Nov 21 '13 at 07:31
  • 3
    How do you do this in Objective-C code? I don't use the Interface Builder / Storyboard / WYSIWYG editor. – Pwner Nov 22 '13 at 00:14
  • Note: you will need to select the "update frames" option on the UIProgressView after adding the vertical constraint. – Senseful Jun 13 '14 at 16:26
  • 14
    works but gives me a warning about a misplaced view... anyway to fix this? – fabian789 Oct 10 '14 at 09:24
  • I use this approach, when setting `progressTintColor` I sometimes get `Error>: CGContextAddPath: invalid context 0x0` – onmyway133 Jun 14 '15 at 04:58
  • 1
    Anyone else finding that the UIProgressView is tapered at the sides when stretched? Almost as if there is a tiny misalignment that becomes more prominent when stretching it up. – Chris Villa Dec 03 '15 at 10:49
47

Whereas others have reported that a CGAffineTransform() works as well:

[self.progressView setTransform:CGAffineTransformMakeScale(1.0, 3.0)];
kleopatra
  • 51,061
  • 28
  • 99
  • 211
user3189408
  • 471
  • 4
  • 2
  • 1
    This is how I did it. Also, this method works even if you don't have auto layout turned on. – NickEntin Mar 13 '14 at 09:14
  • Great solution since the CGAffineTransform data structure represents a matrix used for affine transformations. Basically *CGAffineTransformMakeScale* takes 2 arguments: The factor by which to scale the x-axis and the y-axis, of course the height is the y-axis argument. – OhadM Jul 27 '15 at 08:36
2

Already answered here How to increase height of UIProgressView

@implementation UIProgressView (customView)

- (CGSize)sizeThatFits:(CGSize)size 
{
   CGSize newSize = CGSizeMake(self.frame.size.width,9);
   return newSize;
}

@end
Community
  • 1
  • 1
Shoaib
  • 1,295
  • 15
  • 22
2

Here's the Swift version of user3189408 and Rushabh's great solutions for newer developers and swift enthusiasts like me. Tested for iOS 7+/Swift 2.0.

    progressView.transform = CGAffineTransformMakeScale(1.0, 5.0)
Kevin Kong
  • 29
  • 3
2

Swift 3.x

progressView.transform = CGAffineTransform(scaleX: 1.0, y: 5.0)
FelixSFD
  • 6,052
  • 10
  • 43
  • 117
Ning
  • 148
  • 1
  • 10
0

You can note that frame cannot be set by appearance accessor. You have to set it on each progress view separately.

Usually, the height is set depending on progress bar style.

- (id)initWithProgressViewStyle:(UIProgressViewStyle)style; // sets the view height according to the style
Sulthan
  • 128,090
  • 22
  • 218
  • 270
0

If you're using Autolayout, then the solution is simple: create a height constraint as explained by one of the answers here.

However, chances are you're here because you're creating the progress bar in code.

In this case, solving this through the transform method is not ideal if the view has round corners, since CGAffineTransform will mess with how the corner radius is drawn.

I would subclass the UIProgressView as follows:

class ProgressBarThick: UIProgressView {
    
    var height : CGFloat = 12
    var width: CGFloat = 0.0
    
    override func sizeThatFits(_ size: CGSize) -> CGSize {
        return CGSize(width: width,
                      height: height)
    }
}

Set the height and width before drawing the view.

Wassim
  • 123
  • 1
  • 7