css - Angular 半径不起作用?

标签 css swift

我正在尝试设置一个圆形 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/

相关文章:

asp.net - ASP 按钮文本的 CSS 选择器

ios - 授权回调URL GitHub

ios - 快速获取特定日期和时间的 UTC 时间?

css - 如何在 Vaadin 7 中水平对齐组件与 CSS 布局?

swift - Swift 2.0 中的回调函数

ios - 我应该选择 ViewController 还是 TableViewController?

ios - ArcGis Runtime 100 中的图层名称不同

html - 内联中心三图像

html - 我如何强制 float DIV 匹配另一个 float DIV 的高度?

javascript - 将选项卡更改为 Accordion - 单击时 Accordion 菜单不会折叠