OGeek|极客世界-中国程序员成长平台

标题: ios - 更改 UIProgressbar 的高度并给出边框和角半径 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:00
标题: ios - 更改 UIProgressbar 的高度并给出边框和角半径

目前,我正在使用 UIProgressView,我需要更改 UIProgressView 的高度。我通过下面的代码实现。

extension UIProgressView {

@IBInspectable var barHeight : CGFloat {
    get {
        return transform.d * 2.0
    }
    set {
        // 2.0 Refers to the default height of 2
        let heightScale = newValue / 2.0
        let c = center
        transform = CGAffineTransform(scaleX: 1.0, y: heightScale)
        center = c

        self.layer.cornerRadius = 20.0

    }
  }
}

但是当我将 cornerRadius 设置为 UIProgressView 时不会受到影响。



Best Answer-推荐答案


你还需要告诉它在设置cornerRadius之后不要画到它的边界之外。

//this is on the layer level

self.progressView.layer.masksToBounds = true

//another way is to use clipToBounds
self.progressView.clipsToBounds = true

关于ios - 更改 UIProgressbar 的高度并给出边框和角半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44860309/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4