我有一個圖像視圖的自定義表格視圖單元格。我試圖讓圖像視圖呈圓形,但不是圓形的,我無法確定問題。Round UIImageView
import UIKit
class LegislatorImageCell: UITableViewCell {
@IBOutlet weak var repImageView: UIImageView!
@IBOutlet weak var repOfficeLabel: UILabel!
@IBOutlet weak var repNameLabel: UILabel!
@IBOutlet weak var repPartyLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
repOfficeLabel.textColor = .white
repNameLabel.textColor = .white
repPartyLabel.textColor = .white
repImageView.layer.cornerRadius = repImageView.frame.height/2
repImageView.clipsToBounds = true
repImageView.layer.borderWidth = 2.0
repImageView.layer.borderColor = UIColor.white.cgColor
repImageView.backgroundColor = UIColor.clear
print("HEIGHT: \(repImageView.frame.height)")
print("WIDTH: \(repImageView.frame.width)")
print("CORNER RADIUS: \(repImageView.layer.cornerRadius)")
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
以下是打印語句的結果。
HEIGHT: 125.0
WIDTH: 125.0
CORNER RADIUS: 62.5
嘗試添加'repImageView.layer.masksToBounds = FALSE' –
你確定了ImageView的高度等於它的寬度是多少? –
@AhmadF是的。我按照我的問題中提到的那樣打印兩個值。 – raginggoat