Note that there are some explanatory texts on larger screens.

plurals
  1. POSet a gradient Background to ImageView, rotation
    primarykey
    data
    text
    <p>I want to set a gradient Background to my ImageView. I found a solution for that here on Stack Overflow. But it doesn't really satisfy my needs.</p> <p>I want the gradient to be from left to right. With my the code I found I am only able to fill it from top to bottom. </p> <p>I create the gradient layer with this code:</p> <pre><code>+ (CAGradientLayer *)colorGradientWithColor:(UIColor *)color { UIColor *colorOne = color; UIColor *colorTwo = [UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:0.0f]; NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor, nil]; NSNumber *stopOne = [NSNumber numberWithFloat:0.0]; NSNumber *stopTwo = [NSNumber numberWithFloat:0.9]; NSArray *locations = [NSArray arrayWithObjects:stopOne, stopTwo, nil]; CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.colors = colors; gradientLayer.locations = locations; return gradientLayer; } </code></pre> <p>Then I add the layer to my <code>UIImageView</code>:</p> <pre><code>CAGradientLayer *gradientLayer = [BackgroundGradient colorGradientWithColor:difficultyColor]; gradientLayer.frame = myImageView.bounds; [myImageView.layer insertSublayer:gradientLayer atIndex:0]; </code></pre> <p>And here is the result:</p> <p><img src="https://i.stack.imgur.com/rgj1x.png" alt="enter image description here"></p> <p>And here my interface setup:</p> <p><img src="https://i.stack.imgur.com/9nQSL.png" alt="enter image description here"></p> <p>As you can see, there a two <code>UIImageViews</code>. I want to rotate the layer in the gradient view, so it goes from left to right and not how it is now. </p> <p>With the following code fragment I am able to rotate the whole <code>ImageView</code>. This only kind of solves my problem, but I don't want that, because it kind of destroys my interface..</p> <pre><code>myImageView.transform = CGAffineTransformMakeRotation(M_PI*1.5f); </code></pre> <p>So basically I am searching for a solution to do the gradient from left to right instead from the top to the bottom.<br> Do you guys have any ideas? I am new to XCode and would appreciate every tip!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload