Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Call initWithFrame of Objective C UIView in Swift

Tags:

ios

swift

uiview

This is how I called the UIView DraggableViewBackground in Obejective C and it is working perfectly but how to do the same in Swift

 DraggableViewBackground *draggableBackgroundforurl = [[DraggableViewBackground alloc]initWithFrame:self.view.frame];

My DraggableViewBackground is in Objective C and I want set this as a subview on click of a button

like image 872
Amey Avatar asked Jun 17 '15 00:06

Amey


2 Answers

let draggableBackgroundforurl = DraggableViewBackground(frame: self.view.frame);

That should do the trick.

You can look up the difference between let and var to decide what works best for your needs in that case. let can't change, var can.

like image 180
Kris Gellci Avatar answered Sep 19 '22 02:09

Kris Gellci


From the UIView docs. Just use the normal swift initializer.

enter image description here

like image 41
JordanC Avatar answered Sep 20 '22 02:09

JordanC