【问题标题】:Swift white background from rounded image圆形图像的快速白色背景
【发布时间】:2019-12-16 14:29:22
【问题描述】:

所以我使用以下代码从 Facebook 个人资料图像创建圆形图像。

问题是当 iOS 切换到暗模式时,它有这些不应该存在的白角。我想知道如何摆脱这个白色背景,因为它应该是导航栏的背景颜色,它会根据白天或夜晚而变化。

let fbID = ((result! as AnyObject).value(forKey: "id") as? String) ?? ""
                let facebookProfileUrl = "http://graph.facebook.com/\(fbID)/picture?type=large"
                print(facebookProfileUrl)

                //GRAB IMAGE AND TURN TO BUTTON
                let fburl = URL(string: facebookProfileUrl)
                // Image needs to be added to project.

                self.button.frame = CGRect(x: 0, y: 0, width: 31, height: 31) //set the frame
                let fbs = CGSize(width: 31, height: 31)
                let processor = DownsamplingImageProcessor(size: fbs)
                |> RoundCornerImageProcessor(cornerRadius: 20)
                  let modifier = AnyImageModifier { return $0.withRenderingMode(.alwaysOriginal) }
                self.button.kf.setImage(with: fburl,for: .normal, options: [.processor(processor),.imageModifier(modifier)])
                self.button.addTarget(self, action:  #selector(FirstViewController.signOut(_:)), for: .touchUpInside)
                 let barButton = UIBarButtonItem()
                barButton.customView = self.button
                 self.tabBarController?.navigationItem.rightBarButtonItem = barButton
                //END FACEBOOK PROFILE IMAGE

【问题讨论】:

  • 签出this
  • 启用 UIImageView 的 clipToBound 属性。 self.image.clipsToBounds = true

标签: ios swift kingfisher


【解决方案1】:

试试这个,希望对你有帮助。

    self.button.frame =  UIImageView(frame: CGRect(x: 0, y: 0, width: 31, height: 31));
    let roundCornerIP = RoundCornerImageProcessor(cornerRadius: 20);
    self.button.kf.setImage(with: fburl,options: [.processor(roundCornerIP),.cacheSerializer(FormatIndicatedCacheSerializer.png)]);


    let barButton = UIBarButtonItem();
    barButton.customView = button;
    self.tabBarController?.navigationItem.rightBarButtonItem = barButton;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 2011-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多