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

标题: ios - ImageView 双边框 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:24
标题: ios - ImageView 双边框

我正在调用一个设置 UIImageView 的函数:

func setupImageView(_ imageView: UIImageView) {}

我想给那个 UIImageView 一个图像,把它的角弄圆,并给它两个不同的边框。

这是我目前正在做的事情:

imageView.image = imageConstants.imageThatIsWanted
imageView.clipsToBounds = true
imageView.layer.cornerRadius = imageView.frame.height / 2
imageView.layer.borderWidth = 3.0
imageView.layer.borderColor = UIColor.white.cgColor

在白色边框周围应用第二个蓝色边框颜色的最佳方法是什么?

我尝试创建一个子图层作为 CALayer 并给它一个蓝色边框,但这在图像后面,也在白色边框内。我还尝试绘制 UIBezierPath,但它也位于白色边框内。



Best Answer-推荐答案


import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var secondView: UIView!
    @IBOutlet weak var imgView: UIImageView!
    override func viewDidLoad() {
        super.viewDidLoad()
        imgView.layer.cornerRadius = imgView.frame.size.height/2
         secondView.layer.cornerRadius = secondView.frame.size.height/2
        imgView.layer.borderWidth = 5.0
        imgView.layer.borderColor = UIColor.red.cgColor
        imgView.clipsToBounds = true
         secondView.clipsToBounds = true
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

enter image description here

关于ios - ImageView 双边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47703742/






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