我试图将UIBarButtonItem的背景图像设置为我已经在应用程序中的其他地方成功显示的图像,但我得到了一个奇怪的伸展,我似乎无法解决。同时,我正试着把照片裁剪成一个圆圈。
下面是我的代码:
var profileView : UIView = self.profilePhoto.valueForKey("view") as UIView
var profileImage = (user.valueForKey("profile_photo") as UIImage)
var width = profileView.bounds.size.width
var size = CGSize(width: width, height: width)
UIGraphicsBeginImageContextWithOptions(size, false, 1.0)
UIBezierPath(roundedRect: profileView.bounds, cornerRadius: width / 2).addClip()
profileImage.drawInRect(profileView.bounds)
println("width: \(profileImage.size.width), height: \(profileImage.size.height)")
// Show image without any cropping
//self.profilePhoto.setBackgroundImage(profileImage, forState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)
self.profilePhoto.setBackgroundImage(UIGraphicsGetImageFromCurrentImageContext(), forState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)
UIGraphicsEndImageContext()


发布于 2014-11-30 19:02:53
尝尝这个
self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIGraphicsGetImageFromCurrentImageContext(), style: UIBarButtonItemStyle.Plain, target: nil, action: nil)https://stackoverflow.com/questions/25432497
复制相似问题