【问题标题】:Make circular photos downloaded from google (google places, swift)制作从 google 下载的圆形照片(google places,swift)
【发布时间】:2017-11-12 17:46:19
【问题描述】:

我正在使用 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 类放在情节提要的图像视图中,我下载的照片始终是方形的

【问题讨论】:

    标签: ios swift uitableview swift3 google-places-api


    【解决方案1】:

    您需要将clipsToBounds 设置为true。你可以在设置cornerRadius时这样做:

    @IBInspectable var cornerRadius: CGFloat = 0 {
        didSet {
            self.layer.cornerRadius = cornerRadius
            self.clipsToBounds = true
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多