1

So I am using the following code to create a rounded image from a Facebook profile image.

The issue is when iOS switches to dark mode it has these white corners which should not be there. I am wondering how do I get rid of this white background since it should be the background color of the navigation bar which changes depending on day or night.

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

enter image description here

RussellHarrower
  • 6,470
  • 21
  • 102
  • 204
  • Check [this](https://stackoverflow.com/questions/44675108/kingfisher-3-0-ios-swift-roundcornerimageprocessor-white-background) out – Sayooj Dec 16 '19 at 06:01
  • enable clipToBound proprty of UIImageView. `self.image.clipsToBounds = true` – KKRocks Dec 16 '19 at 06:25

1 Answers1

2

Try This, I hope this may be helpful to you.

    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;
Abhishek Patel
  • 121
  • 1
  • 1
  • 11