我有IBOutlet
imageProfile(UIImageView
)。
当我在代码中设置框架时,我的UIImageView
框架未更新,但我的图层已更新,
你能告诉我为什么吗?
@IBOutlet weak var imageProfile: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
setDesign()
}
func setDesign() {
var newFrame=imageProfile.frame
newFrame.origin.x=50
newFrame.origin.y=100
newFrame.size.width=150
newFrame.size.height=150
imageProfile.frame=newFrame
imageProfile.layer.borderColor = UIColor.whiteColor().CGColor
imageProfile.backgroundColor=UIColor.blackColor()
imageProfile.layer.cornerRadius = 75
imageProfile.layer.borderWidth=3
imageProfile.clipsToBounds = true
imageProfile.updateConstraints()
}
如果我删除IBOutlet
并尝试此操作,我的框架会更新:
var imageProfile: UIImageView?
override func viewDidLoad() {
super.viewDidLoad()
setDesign()
}
func setDesign() {
var image: UIImage = UIImage(named: "iconSuggestSelect.png")!
imageProfile = UIImageView(image: image)
imageProfile!.frame = CGRectMake(100,100,100,200)
imageProfile!.layer.borderColor = UIColor.whiteColor().CGColor
imageProfile!.backgroundColor=UIColor.blackColor()
imageProfile!.layer.cornerRadius = 75
imageProfile!.layer.borderWidth=3
imageProfile!.clipsToBounds = true
imageProfile!.updateConstraints()
imageCover.addSubview(imageProfile!)
}