Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gradient layer accessors #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

glm4
Copy link
Contributor

@glm4 glm4 commented Jul 15, 2020

Gradient attributes accessors

  • Added accessors to all gradient attributes to allow updating the gradient layer as needed.
  • Improved angle setter with a more accurate(Mathematical) solution.
  • Updated example app to showcase accessors usage.
  • Added tests for new accessors.

let randomChange = arc4random_uniform(4)
switch randomChange {
case 0:
self.gradientLayer.uiColors = [UIColor.random, UIColor.random]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self not needed

var degrees = CGFloat(atan2(product, determinant)) * 180 / CGFloat.pi
if degrees < 0 { degrees = 360 + degrees }

return degrees.truncatingRemainder(dividingBy: 360)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add radToDegrees and degreesToRad helpers?

Comment on lines +107 to 128
switch ang {
case 0...45, 315...360:
return isStartPoint ?
CGPoint(x: 0, y: n * tanx(ang) + n) :
CGPoint(x: 1, y: n * tanx(-ang) + n)
case 45...135:
return isStartPoint ?
CGPoint(x: n * tanx(ang - 90) + n, y: 1) :
CGPoint(x: n * tanx(-ang - 90) + n, y: 0)
case 135...225:
return isStartPoint ?
CGPoint(x: 1, y: n * tanx(-ang) + n) :
CGPoint(x: 0, y: n * tanx(ang) + n)
case 225...315:
return isStartPoint ?
CGPoint(x: n * tanx(-ang - 90) + n, y: 0) :
CGPoint(x: n * tanx(ang - 90) + n, y: 1)
default:
return isStartPoint ?
CGPoint(x: 0, y: n) :
CGPoint(x: 1, y: n)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to decide to believe you 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will post the source fro you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants