I want to mimic what seem to be the standard UI for using the UISearchBar, and right now I trying to make the rest of the view gray, when I begin searching, and I tried doing that by just setting the background color of the view to gray, but I am using sections in my UITableView, and they are not turning gray. Anybody have any reasons why that is?
The reason you're not seeing the section headers fade to gray is because they are drawn on top of the gray background, and are opaque; in other words, their alpha is 1.
If you're looking for a suggestion to get the effect you want, my first reflex would be to add an overlay UIView as a subview of the area you want to be "grayed out", and change its background color when certain events occur. Something like this:
// You have to choose what view is the one that needs to be grayed out.
// I'll call the view you want to gray out "viewToBeGrayed"
UIView *grayOverlay = [[UIView alloc] initWithFrame:viewToBeGrayed.frame];
// Initially, the overlay should be clear
[grayOverlay setBackgroundColor:[UIColor clearColor]];
[viewToBeGrayed addSubview:grayOverlay];
Then, when you want to "gray out" viewToBeGrayed, just change the background color of grayOverlay to some translucent gray value:
[grayOverlay setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.5]];
Finally, when you want to get rid of the "grayed out" effect, just set the view back to clear:
[grayOverlay setBackgroundColor:[UIColor clearColor]];
That should be a good place to start. Comment if you need any additional help.
Use the standard UISearchController for your tableview search needs.
Related
I'd like to use this same solution with my UIView to get the same result.
I have a UIView with a UIScrollView. These are embedded in a UINavigationController.
A customer adds an item to their basket and I would like to give them a confirmation message. Right now a little basket UIBarButtonItem updates a title within to show the number of items. This is fine but not every user/customer will notice this.
I don't really like the style of a UIAlertView for this situation. So I'm going to add my own UIView and style it how I want to.
I'm trying to figure out how to get the UIView to show up in the center of the window. Whether the customer is using an iPhone4 or iPhone5.
UIView code:
UIView *confirmationPopup = [[UIView alloc] initWithFrame:CGRectMake(10, 200, 300, 100)];
[confirmationPopup setBackgroundColor:[UIColor redColor]];
// confirmationPopup.center = [confirmationPopup.superview convertPoint:confirmationPopup.superview.center fromView:confirmationPopup.superview.superview];
[[[self navigationController] view] addSubview:confirmationPopup];
The popup view is centered horizontally automatically but not vertically. I've tried to play around with the line you can see I've commented out but it doesn't center the UIView in the center of the window. It appears to be centering it inside the NavBar
Would appreciate some solutions.
Don't hard-code; use auto layout. You might be helped by my custom class for this purpose, an imitation alert view substitute that you can configure however you like. It takes advantage of iOS 7 custom presentation view transitions. (Of course in iOS 8 there will be even more support for this kind of thing, i.e. UIPresentationController.)
I have a probem like this. We know we can make transparent an UIView by changing Alpha value of that view. But I dont want to make transparent buttons which are inside that view. My problem is when I set the parent view alpha, button also get transparent and button title not visible clearly. How can I overcome this problem.
Set the background color of the UIView with variable alpha, like this:
view.backgroundColor = [[UIColor white] colorWithAlphaComponent:0.5f];
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)
I'm working on some drawing code. I have that portion working great.
I want to draw over an image, but I want to still be able to see the detail of the image, the black lines, etc.
What I am working on is making a transparent UIImageView that holds the image.
I'm not sure how to get this set up properly though.
Should this be added above the other UIImageView that I color on or below it?
Here's what I have so far:
- (void)viewDidLoad
{
[super viewDidLoad];
topImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 46, 320, 370)];
[topImageView setImage:[UIImage imageNamed:#"imagesmall.png"]];
topImageView.alpha = 1.0;
topImageView.layer.opacity = 1.0;
topImageView.layer.opaque = NO;
[self.view addSubview:topImageView];
[topImageView release];
}
Thoughts anyone?
Yes, you can draw views over other views. They are drawn in the order that they're added as subviews, unless you reorder them after that.
You may need to set the opaque property for some views (this is distinct from and overrides their layer opacity), and set their backgroundColor to nil. UIImageView seems to be transparent by default, as long as its image is; some other UIView subclasses are not.
So, just what is your overlay going to be? If you just need to display one image over another, what you have here seems to work already. If you need to draw some lines programmatically, you'll need to do this:
Create a subclass of UIView.
Implement its drawRect method to display the content you need.
When you add your custom view on top of the background image, make sure it is not opaque and has no backgroundColor.
A common problem here is to find that your foreground is working, but the background isn't being loaded properly. To make sure the background is there, set the alpha of the foreground view to 0.5. You won't want to do that in production, but it will allow you to verify that both views exist.
i have a tableview and i wish to customize accessoryview button.
For that i have custom PNG image with semi-transparent pixels.
UIButton *myAccessoryButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
[myAccessoryButton setUserInteractionEnabled:YES];
[myAccessoryButton setBackgroundColor:[UIColor clearColor]];
[myAccessoryButton setImage:[UIImage imageNamed:#"accessory_btn"] forState:UIControlStateNormal];
[myAccessoryButton addTarget: self
action: #selector(accessoryButtonTapped:withEvent:)
forControlEvents: UIControlEventTouchUpInside];
[cell setAccessoryView:myAccessoryButton];
And that works fine for me button draws, except one trouble. In my template (PSD) this button has blend mode - overlap, and when i export that button from PSD format it have white semi-transparent pixels which must blends with table background in same overlap blend-mode. But by default exported PNG blends in default mode when i load it as UIImage to customize my accessoryview.
How to change blend mode of UIImage or UIButton or AccessoryView may be?
Is the picture on the left what you get in Photoshop? You want it to brighten the background without altering its hue? If so, there's no easy way to achieve that.
There are two partial solutions:
Have a single drawRect block (or its CALayer equivalent) which draws the background and the draws the glow using the appropriate CGBlendMode.
Edit the picture so the glow at the bottom is the shade of brown of your current background.
Either way, you lose flexibility; it would be nice to drag around your buttons or change the background graphic and have everything merge together nicely.
This may change. CALayer already has a property called compositingFilter. However, as of iOS 5.1, its behavior is undefined. If anyone reads this in a future where iOS does have compositing filter that work, please add a comment to say so.