【问题标题】:Objective-C: Progress view programmaticallyObjective-C:以编程方式查看进度
【发布时间】:2016-07-22 11:39:52
【问题描述】:

如何在我的 Xcode 项目中以编程方式创建高度为 50 和圆角的 progressView

如果我使用此代码

CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 3.0f);  
progressView.transform = transform;

圆角消失

【问题讨论】:

  • 这个问题不能解决我的问题。我无法以编程方式更改高度
  • 如果您的问题是您无法更改高度,那么您应该在问题中提及。有人怎么可能从问题中弄清楚这一点?
  • 检查我的答案 user214155。

标签: ios objective-c progress


【解决方案1】:

我尝试使用圆角获取进度视图。我明白了。

首先你需要添加和导入

#import <QuartzCore/QuartzCore.h>

然后

UIProgressView *progressView;
progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
progressView.progressTintColor = [UIColor colorWithRed:187.0/255 green:160.0/255 blue:209.0/255 alpha:1.0];
[[progressView layer]setFrame:CGRectMake(20, 50, 200, 200)];
[[progressView layer]setBorderColor:[UIColor redColor].CGColor];
progressView.trackTintColor = [UIColor clearColor];
[progressView setProgress:(float)(50/100) animated:YES];  ///15

[[progressView layer]setCornerRadius:progressView.frame.size.width / 2];
[[progressView layer]setBorderWidth:3];
[[progressView layer]setMasksToBounds:TRUE];
progressView.clipsToBounds = YES;

[self.view addSubview:progressView];

还有

KAProgressLabel

Circular Progress View

Progress View Using Bezir Path

【讨论】:

    【解决方案2】:
     UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:whateverStyle]
    progressView.progress = 0.75f;
    

    //设置高度和角

    [[UIProgressView appearance] setFrame:CGRectMake(20, 100, 280, 50)];
    [progressView.layer setCornerRadius:4];
     progressView.layer.masksToBounds = TRUE;
     progressView.clipsToBounds = TRUE;
    
    [self.view addSubview: progressView]
    

    【讨论】:

    • 高度不变
    • 如果你想改变高度,那么你必须通过自定义的draw方法来实现它。
    • 是的,但是圆角会随着您的自定义绘制方法消失
    • 这是一个允许设置高度的第三方进度条。 github.com/yannickl/YLProgressBar
    【解决方案3】:

    您可以使用此代码:

    UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
        progressView.progress = 0.75f;
        [progressView.layer setCornerRadius:10];
        progressView.layer.masksToBounds = TRUE;
       progressView.clipsToBounds = TRUE;
        CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 10.0f);
        progressView.transform = transform;
    
        [self.view addSubview: progressView];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-09
      • 2019-01-30
      • 1970-01-01
      • 2013-04-06
      • 2012-03-30
      • 1970-01-01
      相关资源
      最近更新 更多