我正在使用google地方,我有一个带有tableView的VC,我从用户位置下载了附近的地方,在tableView的每个单元格中我添加了地点和照片的信息。我创建了一个自定义类来使照片循环
import UIKit
@IBDesignable
class RoundImage: UIImageView {
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
self.layer.cornerRadius = cornerRadius
}
}
@IBInspectable var borderWidth: CGFloat = 0 {
didSet {
self.layer.borderWidth = borderWidth
}
}
@IBInspectable var borderColor: UIColor = UIColor.clear {
didSet {
self.layer.borderColor = borderColor.cgColor
}
}
}
但问题是我下载了这个类的地方的照片
import UIKit
private let widthKey = "width"
private let heightKey = "height"
private let photoReferenceKey = "photo_reference"
class QPhoto: NSObject {
var width: Int?
var height: Int?
var photoRef: String?
init(photoInfo: [String:Any]) {
height = photoInfo[heightKey] as? Int
width = photoInfo[widthKey] as? Int
photoRef = photoInfo[photoReferenceKey] as? String
}
func getPhotoURL(maxWidth:Int) -> URL? {
if let ref = self.photoRef {
return NearbyPlaces.googlePhotoURL(photoReference: ref, maxWidth: maxWidth)
}
return nil
}
}
我想知道如何调整它,因为使用这个类我下载的照片即使我将RoundImage
类放在故事板中的imageview上也总是正方形
答案 0 :(得分:0)
您需要将clipsToBounds
设置为true
。您可以在设置cornerRadius
:
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
self.layer.cornerRadius = cornerRadius
self.clipsToBounds = true
}
}