gpt4 book ai didi

css - Angular 半径不起作用?

转载 作者:行者123 更新时间:2023-11-28 10:52:33 32 4
gpt4 key购买 nike

我正在尝试设置一个圆形 ImageView ,当我设置 Angular 半径来执行操作时,它什么也没做。我看过各种线程和解决方案,但都没有用

import UIKit

class AlterProfileViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
view?.backgroundColor = UIColor.white
navigationItem.title = "Profile Settings"
view.addSubview(selectProfileImage)


///Constraints for all views will go here

_ = selectProfileImage.anchor(view.centerYAnchor, left: view.leftAnchor, bottom: nil, right: nil, topConstant: -275, leftConstant: 135, bottomConstant: 0, rightConstant: 0, widthConstant: 100, heightConstant: 100)

// selectProfileImage.layer.cornerRadius = selectProfileImage.frame.size.width/2

///////////////////////////////////////////////


// Do any additional setup after loading the view.
}





override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


//Where all buttons and labels will be added

//will just be a nice looking image view to be next to the profile settings button
lazy var selectProfileImage: UIImageView = {
let selectPicture = UIImageView()
// self.selectProfileImage.layer.cornerRadius = self.selectProfileImage.frame.size.width / 2;
selectPicture.image = UIImage(named: "Paris")

// selectPicture.layer.cornerRadius = selectPicture.frame.size.width / 2;
selectPicture.clipsToBounds = true
selectPicture.translatesAutoresizingMaskIntoConstraints = false
selectPicture.contentMode = .scaleAspectFill
selectPicture.layer.shouldRasterize = true
selectPicture.layer.masksToBounds = true
return selectPicture
}()

///////////////////////////////////////////////////////////////////////////////////



}

这些方法似乎都行不通,我现在真的有点难过

最佳答案

鉴于您使用 AutoLayout 进行布局,我怀疑在计算半径时 ImageView 的大小不正确。 ImageView 初始化为 0,0 大小,因此计算出的半径也将为 0。相反,在调用 super 之后移动 viewDidLayoutSubviews 中的半径计算:

func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

selectProfileImage.layer.cornerRadius = selectProfileImage.frame.size.width / 2;
selectProfileImage.layer.masksToBounds = true
}

关于css - Angular 半径不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45409753/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com