0

I want to place view or imageview objects as subviews of my view. My problem is that I want view that is custom shaped.

For ex: a rectangle

Imageview frame is : x:10, y:30, width:40, height:20

Desired output

Imageview frame: (10:30),(50:30),(10:50),(50:50)

And many different shapes depending on points of the frame

Masashi
  • 350
  • 4
  • 15
  • well just add the subviews to it and use autolayout to put it wherever you want.. frames are set with respect to the `superview` frame, so I don't really understand what is your problem here – Milan Nosáľ Jan 23 '18 at 10:38
  • My problem is that if I want a uiview shaped like a star, how to do it? I want it as a view, don't want to draw it. – Masashi Jan 23 '18 at 10:39
  • Well, there is no way from your question to deduce that you want to draw a star (you should update it to make it clear).. anyway, you will need to learn how to use `draw` methods to draw a custom view, take a look for example here: https://www.scalablepath.com/blog/creating-ios-custom-views-uikit/ – Milan Nosáľ Jan 23 '18 at 10:43
  • I dont mean a star, but I gave example as i want to have a uiview based on points not just x y with height – Masashi Jan 23 '18 at 10:44
  • Anyway thanks, will check the drawing – Masashi Jan 23 '18 at 10:44
  • I worked it as drawing, but 2 issues im having now, first i have to know width and length of the view beforehand which leads to next issue, the view is fully touchable; I want only the drawn part to be touchable. – Masashi Jan 23 '18 at 11:21
  • I guess you can solve it by overriding `hitTest` to detect if the hit was inside the drawn part or not.. why would you need to know the size beforehand? when the `draw` method on the `UIView` is called, the view should have its frame set. – Milan Nosáľ Jan 23 '18 at 11:30
  • Can you provide a code example? Put it as an answer please – Masashi Jan 23 '18 at 11:32
  • I've never really done it before.. those were just ideas on how I would try to approach it.. plus I would check these two questions, cause I think you want something very similar: https://stackoverflow.com/questions/33309465/recognizing-touch-events-only-inside-the-masked-view and https://stackoverflow.com/questions/13291919/detect-touches-only-on-non-transparent-pixels-of-uiimageview-efficiently – Milan Nosáľ Jan 23 '18 at 11:38

0 Answers0