0

I am new to ios/iphone development.

I would like to display a view consisting of the 3 possible line join styles as below. Ideally I would have 3 objects that resemble the 3 drawings below and clicking on each would select the appropriate join.

Is it possible to implement each of these objects with a UIButton or is it better to draw and figure out which one the user touched?

enter image description here

JennyToy
  • 588
  • 4
  • 19

2 Answers2

1

You could use a couple of approaches (and probably more).

You could create custom views and attach a shape layer to each, configured with the desired join, and install the same path into each. You'd then need to attach a tap gesture organizer.

The easiest way, though, would be to simply use custom buttons with static images of your different joins. Then you'd just attach an action to each button like normal.

I would recommend buttons with custom images. It's simple, it's easy, and you end up with normal-behaving buttons.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • True. I should have said that you could create a custom view and implement the `layerClass() ` method to make the view's backing layer a `CAShapeLayer`. Clarification, layers have `CGPath`s, not `UIBezierPath`s. (But `UIBezierPath`s contain a `CGPath` internally, so the distinction isn't a big deal.) – Duncan C Jan 31 '17 at 20:53
1

You can certainly use three custom buttons and make each of the three mitre drawings the image of one button.

For best results, in my opinion, you should learn to draw in code and actually draw the mitre drawings in code — drawing each of them in to a UIImage and then making each UIImage the image of a button.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    I can draw several lines but how do I fill in between the lines with some color? – JennyToy Feb 01 '17 at 16:32
  • I don't know what "fill in between the lines with some color" means, and in any case, that was not the question. The question was what strategy to use to construct the interface illustrate, and that is what I was responding to. – matt Feb 01 '17 at 16:42
  • 1
    I think it is obvious from the images in the question what I meant: I can draw the contour lines and the inner lines but how do I paint black in between the contour (again the figures should clarify what I mean) – JennyToy Feb 01 '17 at 18:23
  • 1
    @JennyToy You can try to rotate a CGRect with a given color. Look for example at this link http://stackoverflow.com/questions/18710933/objective-c-how-to-rotate-cgrect. A better way might be to just draw a triangle as in http://stackoverflow.com/questions/30650343/triangle-uiview-swift – user2175783 Feb 01 '17 at 18:48
  • 1
    I don't see any black in any "contour". I see black thick lines, stroked. Basically this is a one-liner to draw any of those drawings (well, maybe four lines of code). Is the problem that you don't know anything about how to draw in code? – matt Feb 01 '17 at 19:28
  • @matt I know how to draw straight lines and arcs. For the first image (miter join) that is 8 straight lines. It would be 9 lines for the third (bevel join). But I think I understand what you are saying (make the lines thick) in which case miter would be 4 lines. – JennyToy Feb 01 '17 at 19:55
  • 1
    "For the first image (miter join) that is 8 straight lines" Right, but I'm telling you no, it's four straight lines each of which is stroked thick. And the same for the other two drawings, because in each case the mitre is a setting and is done for you. – matt Feb 01 '17 at 20:02