iPhone ProgressBar

前端 未结 3 819
轮回少年
轮回少年 2021-02-03 16:33

How can I change the color as well as size of UIProgressBar in iPhone SDK

相关标签:
3条回答
  • 2021-02-03 17:04

    As Can noted, there is very little customization available for UIProgressView... pretty sucky. The solution I just implemented was to hack a UISlider. Here's the inspiration, from Apple's support forum.

    1. Create a new UISlider
    2. Set the setMinimumTrackImage and setMaximumTrackImage to your desired UIImage values
    3. Set the setThumbImage to nil
    4. Set the upper and lower bounds of the slider

    Once this is setup and added to your UIView, use your custom method to set the value of the slider to the value you would normally have assigned to the UIPRogressView's progress.

    0 讨论(0)
  • 2021-02-03 17:11

    You could probably also hack one together using an image that looks like the progress bar at it's smallest size and then create a stretchable image with it.

    UIImage *progressBarImg= [someImage stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0];
    

    Then you could set the image as the backgroundImage for a disabled UIButton and animate the button width incrementally to indicate progress. I haven't tried this, but I think it would work.

    0 讨论(0)
  • 2021-02-03 17:14

    Assuming you mean a UIProgressView, you can resize it as you would any other view, by setting the frame:

    UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
    [progressView setFrame:CGRectMake(0,0,320,10)];
    

    or if you're using the default style, you can set the frame in the init method:

    UIProgressView *progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0,0,320,10)];
    

    As far as I know, the color of a UIProgressView cannot be changed. You'll probably have to roll your own view for that.

    0 讨论(0)
提交回复
热议问题