1

I need to create a ticket in an app, like the image that I've attached. My problem is, that I can't seem to find a solution to make the transparent half-circle-holes, meanwhile making the shadows follow the hole.

Ticket view

The ticketview is going to used in a tableview cell.

My first thought was to make two views, one white, and one green, and then add some background-coloured circular views on the green part - but then the shadow won't look right.

Then I thought about adding it as an image, but I just think this solution is wrong, and not very iOS-developer-ish.. Also this won't scale right on different devices, and I won't be able to align text to the green part etc.

So I'm a little lost - how to fix this job?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nicolai Harbo
  • 1,064
  • 12
  • 25
  • 1
    I would go with images if you could. Drawing things like this is overkill compared to providing a graphic. If you absolutely can't get graphics you could do this with bezier paths. For shadowing with your created view, you then get the CGPath of the view, and draw a shadow along the curve using bezier paths: https://developer.apple.com/library/content/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/BezierPaths/BezierPaths.html –  Jul 10 '17 at 11:06
  • @NicolaiHarbo Where you need to show shadow – Ashok Londhe Jul 11 '17 at 05:34

1 Answers1

1

Please follow the steps to solved your problem:

  1. Take on UIView in you cell - Green view in your case
  2. Add two subviews into it
  3. One on top right and other on bottom right (Add Only half view in top right - remaining half portion of view must be out of your green view)
  4. Add below code to set make it semi circular...

    firstCircleView.layer.cornerRadius = firstCircleView.frame.size.width + 2
    firstCircleView.clipsToBounds = true
    firstCircleView.layoutIfNeeded()
    
    secondCircleView.layer.cornerRadius = secondCircleView.frame.size.width + 2
    secondCircleView.clipsToBounds = true
    secondCircleView.layoutIfNeeded()
    

Notes : You need to create out of both of views.

Prefer Screenshot :

enter image description here

Output:

enter image description here

Note1 : i have added it in UIView instead of it you can add it in UITableViewCell . I have used gray background color in first screenshot for understanding purpose. Please make it to white while running app.

Ashok Londhe
  • 1,491
  • 11
  • 29
  • Working solution i suppose, but it's still not solving the shadow-challenge :/ Thanks for your answer though! – Nicolai Harbo Jul 10 '17 at 17:07
  • @NicolaiHarbo What is the shadowing issue .Please explain so that I will solve that also. and if this solutions is working for you please accept this and up vote. – Ashok Londhe Jul 10 '17 at 17:17
  • I need the shadow to follow the curve of the hole in the buttom.. Exactly like shown on the image :) But I solved my problem with using the image I posted here, and then my designer told me, that the green part was 20% of the length - then I created a transparent view on the white part that is 80% of the length, and another transparent view on the right part that is the last 20%, and then I'm able to add items and use the views to align the elements inside them :) But thanks alot for your effort mate! I really appreciate it! – Nicolai Harbo Jul 11 '17 at 08:44
  • @NicolaiHarbo You are welcome can you up vote my answer if it helps you – Ashok Londhe Jul 11 '17 at 11:29