使用didset函数更新UIImageView

时间:2019-03-28 09:39:51

标签: swift uiscrollview

我使用Scrollview创建了页面结构。我使用didset更新了sectionText和HeaderText,但是无法更新图像。我需要做什么来更新图像?除了图像,一切正常。

class PageView: UIView {

    var headerText: String = "" {
        didSet {
            headerTextField.text = headerText
        }
    }

    var paragraphText: String = "" {
        didSet {
            paragraphTextView.text = paragraphText
        }
    }

    private var cellImage = UIImageView()
     var imagee: UIImage? {
        didSet {
           cellImage.image = imagee
        }
    }

class PageController: UIViewController {

    let placeHolderText = "........"

    let placeHolderText1 = "......"
    var cellImage = UIImage(named: "asdasd")
    var cellImageLogin = UIImage(named: "asdasdff")

 let pageView1 = PageView(headerText: "123123", paragraphText: placeHolderText, backgroundColor: .red, image: cellImage! )
        views.append(pageView1)
 let pageView2 = PageView(headerText: "123213123", paragraphText: placeHolderText1, backgroundColor: .orange, image: cellImageLogin!)
        views.append(pageView2)

1 个答案:

答案 0 :(得分:0)

由于您的cellImage没有frame,因此在您的PageView中不会显示

例如,您需要添加frame

cellImage.frame = CGRect(x: 0, y: 0, width: 100, height: 200)

setup之前的self.addSubview(cellImage)方法中

还需要根据您的要求应用正确的约束。