I have this UINavigationBarButton I am making with an image inside of it that is originally square. I have used this code on other regular buttons and it has made the images round. However, it is not working for this button and I have no idea why. Also, I do not know how to make it smaller. (but don't mind its placement)
func preloadMe() {
let btn1 = UIButton(type: .custom)
let completelink = self.me[0].picture_url
self.loadProfilePhoto(image: btn1, link: completelink)
btn1.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
btn1.layer.cornerRadius = 0.5 * btn1.frame.height
//btn1.setImage(UIImage(named: "profileMenuButton"), for: .normal)
btn1.addTarget(self, action: #selector(HomeViewController.menuClicked), for: .touchUpInside)
let item1 = UIBarButtonItem(customView: btn1)
btn1.contentEdgeInsets = UIEdgeInsetsMake(0, -70, -10, 0)
self.navigationItem.setLeftBarButtonItems([item1], animated: true)
}
func loadProfilePhoto(image: UIButton, link: String) {
image.downloadedFrom2(link: link)
image.imageView!.clipsToBounds = true
image.imageView!.layer.cornerRadius = (image.imageView!.frame.height) / 2
image.imageView!.contentMode = .scaleAspectFill
}
After a suggestion of adding in btn1.backgroundColor = .black
I am now getting this result. What should I do now?