I have a custom view inside a view controller. I'm trying to setting the CGRect of custom view from view controller
I have few more buttons in custom view and i want to position them based on frame's coordinates but in the ovveride draw method, it takes bounds of view.
I want all the view to be drawn using frame coordinates instead of bounds
Pls advice how to acheive that
When you instantiate a view programaticly, you should do the following :
1) define the size of the rectangle that will contain your view.
2) Find the origin of this rectangle (is set to be the upper left corner) in the cartesian system (x,y) of the parent view of the view that you are creating, as function of the width and the height of the parent View .
3) Set the frame of your view as myView.frame = CGRect(origin: myOrigin, size: mySize)
You should always use the 'frame' property to define a new view.
I usually work with custom view, containing themselves many other custom Views, custom Buttons, ... The best way to do so (especially when it's getting complicated), is to take a paper & and pencil, draw the (x,y) axis of the parent View (y points downwards and x points to the right) and find all coordinates of all the origins in terms of the width and the height of the view in which you are working.
When you are working with subclasses of UIView (or any other object) you can easily use the system of coordinate defined at the origin of the view that you are creating (in the draw method
)
Hope this was helpful, you can publish your code if you want more specific help !