amin sadeghian
amin sadeghian

Reputation: 21

How to set new y position ImageView in swift UIView class

import UIKit

class SalamView: UIView {

    @IBOutlet var salamView: UIView!

    @IBOutlet weak var salamLogoIMG: UIImageView!

    var salamLogoImgOrigY: CGFloat!
    var salamLogoImgFromToY: CGFloat!

    override init(frame: CGRect) {
        super.init(frame: frame)
        initializeViews()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        initializeViews()
    }

    private func initializeViews(){
        Bundle.main.loadNibNamed("SalamView", owner: self)
        salamView.clipsToBounds = true
        salamView.setHeight(height: screenSize.height - statusBarHeight)
        salamView.setWidth(width: screenSize.width)
        addSubview(salamView)

        salamLogoImgOrigY = salamLogoIMG.frame.origin.y
        salamLogoImgFromToY = -(salamLogoIMG.frame.size.height + salamLogoImgOrigY)

       salamLogoIMG.frame = CGRect(x: salamLogoIMG.frame.origin.x,
 y: salamLogoImgFromToY,
 width: salamLogoIMG.frame.size.width,
 height: salamLogoIMG.frame.size.height)
    }

}

i need to change y position of salamLogoIMG to salamLogoImgFromToY, if run new position line code in btn action its work, but i need set in first time, please help me

Upvotes: 0

Views: 117

Answers (2)

user7523279
user7523279

Reputation:

ther are problem

salamLogoImgFromToY = -(salamLogoIMG.frame.size.height + salamLogoImgOrigY) salamLogoImgFromToY never (-) minus

Upvotes: 1

Maulik Bhuptani
Maulik Bhuptani

Reputation: 616

Try setting your frame in layoutsubviews method of your UIView class

Upvotes: 0

Related Questions