{"action":"created","issue":{"url":"https://api.github.com/repos/ViccAlexander/Chameleon/issues/32","labels_url":"https://api.github.com/repos/ViccAlexander/Chameleon/issues/32/labels{/name}","comments_url":"https://api.github.com/repos/ViccAlexander/Chameleon/issues/32/comments","events_url":"https://api.github.com/repos/ViccAlexander/Chameleon/issues/32/events","html_url":"https://github.com/ViccAlexander/Chameleon/issues/32","id":83031330,"number":32,"title":"Gradient - change angle (question)","user":{"login":"rjcristy","id":8848965,"avatar_url":"https://avatars.githubusercontent.com/u/8848965?v=3","gravatar_id":"","url":"https://api.github.com/users/rjcristy","html_url":"https://github.com/rjcristy","followers_url":"https://api.github.com/users/rjcristy/followers","following_url":"https://api.github.com/users/rjcristy/following{/other_user}","gists_url":"https://api.github.com/users/rjcristy/gists{/gist_id}","starred_url":"https://api.github.com/users/rjcristy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjcristy/subscriptions","organizations_url":"https://api.github.com/users/rjcristy/orgs","repos_url":"https://api.github.com/users/rjcristy/repos","events_url":"https://api.github.com/users/rjcristy/events{/privacy}","received_events_url":"https://api.github.com/users/rjcristy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-31T07:49:52Z","updated_at":"2015-05-31T12:09:31Z","closed_at":null,"body":"First of all I want to thank you for this wonderful library that makes IOS development easier. \r\n\r\nI would like to ask if Chameleon currently supports altering the angle of a linearGradient UIColor?\r\n\r\nThank you very much!"},"comment":{"url":"https://api.github.com/repos/ViccAlexander/Chameleon/issues/comments/107164005","html_url":"https://github.com/ViccAlexander/Chameleon/issues/32#issuecomment-107164005","issue_url":"https://api.github.com/repos/ViccAlexander/Chameleon/issues/32","id":107164005,"user":{"login":"ViccAlexander","id":1724674,"avatar_url":"https://avatars.githubusercontent.com/u/1724674?v=3","gravatar_id":"","url":"https://api.github.com/users/ViccAlexander","html_url":"https://github.com/ViccAlexander","followers_url":"https://api.github.com/users/ViccAlexander/followers","following_url":"https://api.github.com/users/ViccAlexander/following{/other_user}","gists_url":"https://api.github.com/users/ViccAlexander/gists{/gist_id}","starred_url":"https://api.github.com/users/ViccAlexander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ViccAlexander/subscriptions","organizations_url":"https://api.github.com/users/ViccAlexander/orgs","repos_url":"https://api.github.com/users/ViccAlexander/repos","events_url":"https://api.github.com/users/ViccAlexander/events{/privacy}","received_events_url":"https://api.github.com/users/ViccAlexander/received_events","type":"User","site_admin":false},"created_at":"2015-05-31T12:09:31Z","updated_at":"2015-05-31T12:09:31Z","body":"Glad you find it useful @rjcristy! To answer your question, at the moment there isn't any straightforward way to do this. If you'd like I can add it as a feature for the 2.0 release.\r\n\r\nIf you really need this asap, there is a way. Let's begin by looking at how a linear gradient's direction works. Take the following snippet of code for example:\r\n\r\n``` objective-c\r\n//Set background color for our square view\r\nsquare.backgroundColor = [UIColor colorWithGradientStyle:UIGradientStyleLeftToRight withFrame:square.frame andColors:@[FlatYellow, FlatRed]];\r\n```\r\n\r\nThis will create a gradient that begins on the left side as FlatYellow and ends on the right as FlatRed.\r\n\r\n![square](http://i.imgur.com/IfTJpyH.jpg)\r\n\r\nIf you right-click on *\"colorWithGradientStyle...\"* and select **\"Jump to Definition\"**, you'll see that it'll take you to the method's internal implementation. Scroll down and you'll see the switch statement that contains the `UIGradientStyleLeftToRight` logic. Focus on the highlighted lines below. This is where the magic happens!\r\n\r\n![](http://i.imgur.com/BHoIic0.png)\r\n\r\nSince Chameleon's `gradientColor` is essentially created using a `CAGradientLayer`, it uses [`setStartPoint:`](https://developer.apple.com/library/prerelease/ios/documentation/GraphicsImaging/Reference/CAGradientLayer_class/index.html#//apple_ref/occ/instp/CAGradientLayer/startPoint) and [`setEndPoint:`](https://developer.apple.com/library/prerelease/ios/documentation/GraphicsImaging/Reference/CAGradientLayer_class/index.html#//apple_ref/occ/instp/CAGradientLayer/endPoint) to specify the direction.\r\n\r\nThe values for our `leftToRight` style are as follows: \r\n\r\n``` objective-c\r\n[backgroundGradientLayer setStartPoint:CGPointMake(0.0, 0.5)];\r\n[backgroundGradientLayer setEndPoint:CGPointMake(1.0, 0.5)];\r\n```\r\n\r\nTo make it clearer how direction works take a look below:\r\n\r\n![](http://i.imgur.com/SRYJYa9.jpg)\r\n\r\nAs you can see it's pretty simple to make sense of the grid. Let's try an example. Say you wanted the `FlatYellow` color to begin at the lower left corner and the `FlatRed` color  to end at the top right. All you need to do is update the values based on the coordinate grid above, in order to reflect the new startPoint and endPoint.\r\n\r\n![](http://i.imgur.com/tVYhYJT.png)\r\n\r\nNow update the values to reflect your new points:\r\n\r\n``` objective-c\r\n[backgroundGradientLayer setStartPoint:CGPointMake(0.0, 1.0)];\r\n[backgroundGradientLayer setEndPoint:CGPointMake(1.0, 0.0)];\r\n```\r\n\r\nThe lines above should get you the following:\r\n\r\n![](http://i.imgur.com/esaHwyv.png)\r\n\r\nYou should be able to toy around with this to get the angle you want. I recommend adding a new case to the switch statement to reflect your new custom direction, unless you don't need the leftToRight direction, in which case you can just overwrite its values. \r\n\r\nHope this helps get you started on implementing the look you want. I know it's not the best approach, but I'll definitely explore the idea of make this easier in Chameleon 2.0 if you'd like. Maybe allow users to specify an angle as you mentioned, and handle all the math in the background. What do you think?\r\n\r\n"}}