Is there any way to change the composite mode of a UIView background say to screen, overlay, or multiply?
The effect I am trying to go for is similar to what appears in the iOS notification centre where the cell background is much darker, however still translucent to the background. This looks to me like a multiply effect in photoshop.
I'm not 100% sure what your referring to but play around with the background colour and alpha
view.backgroundColor = [UIColor blackColor];
view.alpha = 0.4f; // Try changing this to suit
They may be using subtle gradients and other additional embellishments to really fine tune the look.
Update
I can get a fairly convincing reproduction using
backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.37f];
whitePixelLine = [UIColor colorWithWhite:0.8f alpha:0.4f];
darkPixelLine = [UIColor colorWithWhite:0.0f alpha:0.6f];
My graphic skills are terrible so this could be way off the mark
Related
I have created a screen tutorial for my app.
I've done this by creating a PageViewController to manage 4 viewControllers.
In the PageViewController I have implemented the following code
self.modalPresentationStyle = UIModalPresentationFormSheet;
I have also set the alpha on the pageViewController view to .45
This makes the PageViewController transparent which is exactly what I want.
However, it is also making everything inside the 4 viewControllers that are being managed by the PageViewController transparent i.e. buttons, labels, etc.
How can I stop all of those object from being transparent?
Views always work like this. If you wanted to make a view semi-transparent, it would usually be pretty vexing if that didn't also affect all of its subviews. The times when you want your alpha setting to also affect the subviews likely far outnumber the times when you don't.
What you can do instead of making the view transparent is to make its background color transparent. That is, instead of:
self.view.backgroundColor = [UIColor blueColor];
self.view.alpha = 0.45;
you can do:
self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:1 alpha:.45];
That way, your subviews are not affected, because while the alpha of your main view's background color is 0.45, the alpha of the view itself is still 1.0.
To change the background color of a view, use the following on the view:
[viewController.view setBackgroundColor:[UIColor COLOR]];
where COLOR is the color you would like (i.e. whiteColor)
How can add a light gray shadow to a UIButton, I don't want a method to do this at the moment, it should be something like:
UIButton *button1... button1.layer.shadowOpacity = 0.8
etc, but that doesn't work, it only adds a shadow inside the button, but I need it on the outside. Thanks!
First you have to #import <QuartzCore/QuartzCore.h>. Then:
mybtn.layer.shadowColor = [UIColor blackColor].CGColor;
mybtn.layer.shadowOpacity = 0.5;
mybtn.layer.shadowRadius = 2;
mybtn.layer.shadowOffset = CGSizeMake(3.0f,3.0f);
You can also use –[UIButton setBackgroundImage:forState:] to set the background image for UIControlStateNormal to one with a shadow. E.g.:
[button setBackgroundImage:[UIImage imageNamed:#"ButtonBackgroundNormal"]
forState:UIControlStateNormal];
where ButtonBackgroundNormal.png has a shadow. Images often render faster than drawing with code. And, speed is important, especially if you're adding it to a UITableViewCell. In that case, to speed up scrolling speed, make sure the background image is completely opaque by designing it with the same background color of the UITableViewCell and saving it without transparency. Then, set button.opaque = YES.
When changing a tab in Twitter for mac , the old view slide to left, and the new view become center. both of old and new view has a shadow behind it.
I'v tried :
viewController.view.layer.masksToBounds = NO;
viewController.view.layer.shadowRadius = 50.0;
viewController.view.layer.shadowColor = [TUIColor blackColor].CGColor;
viewController.view.layer.shadowOpacity = 0.4;
and used viewController.view.layer.shouldRasterize = YES; trying to speed it up.
But still feel lag then twitter for mac.
What's the best performance way to add those shadow?
Have a look at CALayer's shadowPath attribute. Typically if you are willing to tell the layer exactly how the shadow should be drawn then it will be faster than the default, where it tries to calculate a shadow based on the full view alpha channel.
For example:
CGPathRef shadow = CGPathCreateWithRect(CGRectInset(self.bounds, -3, 1), NULL);
[self.layer setShadowPath:shadow];
[self.layer setShadowColor:[[UIColor colorWithWhite:0 alpha:0.5f] CGColor]];
[self.layer setShadowOpacity:0];
[self.layer setShadowRadius:8];
CFRelease(shadow);
(this is iOS code but I believe the only thing you'll need to change is the UIColor reference).
I'm using a background image for my UITableViewCell.
If I just set the background of the cell, but keep everything else the same, I get this:
I'm if I use this code in viewDidLoad and it fixes the cell but it is making the navbar transparent:
self.navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
self.tableView.backgroundColor = [UIColor clearColor];
Is there way to get the navbar back and get the cell looking normal?
For the most part, I don't believe UIPopovers have many visual options as far as background.
See where that ugly yellow is? I need that color to be changing... a lot. Kind of like a trippy kalidascope thing, but with one color the entire time. A lot like the default OS X Spectrum screensaver. How should I go about doing this? Objective-C would seem like a huge CPU hog. Would it be possible for me to put an OpenGL background into something like this? Would love a push in the right direction.
Well you can schedule a function call for like half a second and then change the background color there like this
[NSTimer scheduledTimerWithTimeInterval:0.3f target:self selector:#selector(someMethod) userInfo:nil repeats:YES];
- (void)someMethod
{
self.view.backgroundColor = [UIColor redColor];
}
But this will change the color your background view to only red, so in order to change the color to something else you can declare a class variable or more than one to change the your background color. And in the selector method you can change their value to get some cool effects. You can do something like this.
self.view.backgroundColor = [UIColor colorWithRed:x green:y blue:z alpha:1.0f];
x += 0.01f;
y += 0.02f;
z += 0.04f;
if(x >= 1)
x = 0.01f;
if(y >= 1)
y = 0.02f;
if(z >= 1)
z = 0.04f;
Try the simplest thing first: just set the backgroundColor property on that view and then use performSelector:withObject:afterDelay: to change to the next color after a suitable delay.
Unless you're doing the whole screen with OpenGL, it's not likely to be any faster that way. The bottleneck is most likely compositing the "ball" image and text over the background rather than the creation of a solid-color background. Profile it, instead of guessing or relying on my guessing.
Let's assume the foreground material has transparency. Then we can have a solid view behind it that occupies the entire screen, and we see that view's color thru the foreground material. Then it suffices to change that background view's color. If you wish to animate this change in background color, change the view's layer's backgroundColor (to a CGColor); the effect will automatically be animated. You'll need to link to QuartzCore.framework and import <QuartzCore/QuartzCore.h>, and then you'll be able to say:
theView.layer.backgroundColor = [[UIColor redColor] CGColor];
You can modify this color animation; for example, you can dictate its duration (how fast or slow the color changes) by setting the animation duration for CATransaction (see the CATransaction class methods). I can imagine you'd have a repeating NSTimer, where every time the timer fires you'd do another color-change animation.