How to set imageView in circle like imageContacts in Swift correctly?(如何在 Swift 中正确设置 imageView,如 imageContacts?)
问题描述
我想像图片联系人一样在 imageView 中显示一张图片(在一个圆圈中)但是当我尝试显示这个时,imageView 会重新调整他的大小并且这个在一个圆圈中不能正确显示.
I want to show a picture into imageView like the image contact (in a circle) But when I try to show this, the imageView rescale his size and this doesn't show correctly in a circle.
 image.layer.borderWidth=1.0
 image.layer.masksToBounds = false
 image.layer.borderColor = UIColor.whiteColor().CGColor
 image.layer.cornerRadius = image.frame.size.height/2
 image.clipsToBounds = true
我想这样显示:
但我明白了:
如何将图像调整为 UIImageView 大小以显示为圆形?
How can do the image resize to UIImageView size to show as a circle?
谢谢!
推荐答案
image 使用的 frame 尺寸是多少?如果我将框架设置为正方形,我可以得到一个完美的圆形.
What frame size are you using for image? I can get a perfect circle if I set the frame to be a square.
let image = UIImageView(frame: CGRectMake(0, 0, 100, 100))
                        这篇关于如何在 Swift 中正确设置 imageView,如 imageContacts?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Swift 中正确设置 imageView,如 imageContacts?
				
        
 
            
        基础教程推荐
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
 - Android Volley - 如何动画图像加载? 2022-01-01
 - SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
 - 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
 - iOS - UINavigationController 添加多个正确的项目? 2022-01-01
 - UIImage 在开始时不适合 UIScrollView 2022-01-01
 - 如何将图像从一项活动发送到另一项活动? 2022-01-01
 - Play 商店的设备兼容性问题 2022-01-01
 - 如何比较两个 NSDate:哪个是最近的? 2022-01-01
 - navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				