Question

I am looking to spin a UILabel 45 degrees (to the right) on it's anchor point (the center of the UILabel) and put it on the right of the table cell so it looks like a diagonal ribbon across the table cell, from the bottom-right of the cell up and toward the left until it hits the top of the cell.

To do this (in a diagonal) I do the following:

Get the height of the table cell. This gives me (in an triangle with sides a,b,c) "c". So, "c" is one leg of the triangle. Because I want it to be a 45 degree triangle that also gives me leg "a" of the triangle.

Now the easy part: I know all three angles of this triangle. "C" (angle across from side c) is 45 degrees, "B" (angle across from side "b") is 90 (cos it is the right top corner of the cell's content view...and we know those are right-angles. Angle "A" (angle across from side "a") is also 45.

Side "b" is the side i am having fits with... What formula do i use to get length of side "b" such that it is wide enough to go (when diagonal) across the height of the cell's contentview from the bottom right until it hits the top of the cell? I know for a 44pt high cell, the length of this UILabel when diagonal should be around 60-ish pts...but the formula is escaping me.

When using a online calculator Triangle Calculator and using the drop-down for angle-angle-side, I feed in the following numbers: A: 45,B: 45, C: 44, and this gives: 62.2254 for the side length...which is fine...but my table cell is not always 44pts high so i need a formula i can put in objective-c. I have read up on the Law of Sines, but my High-School Trig years are SO behind me.

I hope all this is clear. If not, please let me know. Thanks in advance.

Was it helpful?

Solution

If I understand you correctly you will always have triangle with one right angle and two other 45 degrees. If short side (both of them will have same length) of such triangle is X, then long side is square root from 2*X*X

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top