gpt4 book ai didi

ios - drawRect 圆角

转载 作者:搜寻专家 更新时间:2023-10-31 22:21:26 28 4
gpt4 key购买 nike

我有 UIVIew 的代码:

override func drawRect(rect: CGRect) {

let toolbarSize = CGFloat(UIDevice.currentDevice().userInterfaceIdiom == .Pad ? 0 : 54)

let width = CGRectGetWidth(self.frame)
let height = CGRectGetHeight(self.frame) - toolbarSize

let heightSpan = floor(height / 2 - self.cropSize.height / 2)
let widthSpan = floor(width / 2 - self.cropSize.width / 2)

// fill outer rect
UIColor(red: 0, green: 0, blue: 0, alpha: 0.5).set()
UIRectFill(self.bounds)

// fill inner border
UIColor(red: 1, green: 1, blue: 1, alpha: 0.5).set()
UIRectFrame(CGRectMake(widthSpan - 2, heightSpan - 2, self.cropSize.width + 4,
self.cropSize.height + 4))

// fill inner rect
UIColor.clearColor().set()
UIRectFill(CGRectMake(widthSpan, heightSpan, self.cropSize.width, self.cropSize.height))
}

这为我的 UIView 绘制了一个带有白色边框的矩形,我想添加一个角半径来绘制一个圆。

这有可能吗?

最佳答案

这很适合我

    someImageView.layer.borderWidth = 1
someImageView.layer.borderColor = UIColor.blackColor().CGColor
someImageView.layer.cornerRadius = someImageView.frame.height/2
someImageView.clipsToBounds = true

关于ios - drawRect 圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34995677/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com