NEW: Learn to build amazing SwiftUI apps for macOS with my new book! >>

Connect two ....addSubview(x,y)

Forums > Swift

Good day. how to connect two teams? I`m newbie

    let importClassUIImage = CreateCardCPU()
    let cardCPUOne = importClassUIImage.CreateCard(positionX: self.buttomStart.frame.minX, positionY: 200, tags: 1)
    self.view.addSubview(cardCPUOne)
    let cardCPUTwo = importClassUIImage.CreateCard(positionX: self.buttomStart.frame.maxX, positionY: 200, tags: 2)
    self.view.addSubview(cardCPUTwo)

    ???self.view.addSubview(cardCPUOne, cardCPUTwo)???

    Thanks

1      

Hello, can you clarify what are you trying to accomplish? What does this CreateCardCPU return?

1      

And what do you mean by "connecting two teams"? Basically you already are adding both views cardCPUOne and cardCPUTwo as a subviews.

1      

class CreateCardCPU { func CreateCard(positionX: CGFloat, positionY: CGFloat, tags: Int) -> UIImageView { var cardCPU = UIImageView() let myCardFrame = CGRect(x: 0, y: 0, width: 142, height: 200) cardCPU = UIImageView(frame: myCardFrame) cardCPU.image = UIImage(named: "back.png") cardCPU.center.x = positionX cardCPU.center.y = positionY cardCPU.tag = tags return cardCPU } }

I thought that you can call two pictures. I wanted to optimize the code

1      

@miff  

[cardCPUOne, cardCPUTwo].forEach { view.addSubview($0) }
// Put constraints for each view here

1      

@miff
Thanks. Very grateful.

1      

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Spend less time managing in-app purchase infrastructure so you can focus on building your app. RevenueCat gives everything you need to easily implement, manage, and analyze in-app purchases and subscriptions without managing servers or writing backend code.

Get Started

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.