iOS 設置圓形頭像遇到的問題總結

今天在工作的時候,需要設置用戶的頭像爲圓形,但是我設置了很久都無效果,代碼如下,效果如下:

    // 添加頭像

    headIcon.image = [UIImage imageNamed:image];

    headIcon.layer.borderColor = [[UIColor whiteColor]CGColor];

    headIcon.layer.borderWidth = 2;

    headIcon.layer.cornerRadius=25;

    headIcon.layer.backgroundColor = [[UIColor whiteColor]CGColor];

    [headView addSubview:headIcon];








後來廢了很大的勁,才找到還需要一句關鍵的代碼,那就是:
imageView.layer.masksToBounds = YES;設置上這一句就好了。效果如下:



發佈了43 篇原創文章 · 獲贊 18 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章