Gray out view in iphone, how? - iphone

I wonder what is the way to gray out portion of a view similar to the way UIAlertView grays out everything except the message box? Right now i use another custom view on top of the target area, but it doesnt look as nice.
Any ideas?

I get good results using the method you have already tried. perhaps fiddling around with the alpha is a good idea?
mask = [[UIView alloc] initWithFrame:window.frame];
[mask setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.78]];
[self.view addSubview:mask];
Then later in your code you can remove it:
[mask removeFromSuperview];
or
[mask setHidden:YES];
If you want to make it even better, I suppose you could try using a gradient, either programmatically, or as an image, and using this to darken the edges of the screen such that the content you are displaying forefront appears to be the light source.

Related

How to use colorWithPatternImage: with UILabel

I am trying to create a UILabel with customized text that shows the current score of a game. The customer has given me screen shots where they would like the color/pattern of the text to be like that of a wooden panel, so it looks to be brownish with darker swirls within it.
Is this even possible? I have spent an enormous amount of time scouring the web for something related to this and have found nothing concrete. One lead I followed that didn't pan out was using:
[UILabel setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed: #"WoodenPanel.png"]]];
It seems like there's a way to use an image and set it as the color for the text. But what results when I use this is a completely black UILabel. Is this on the right track? Or is this simply not possible?
You have to do it like this:
[labelName setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"IMAGENAME.PNG"]]];
NOT like you did:
[UILabel setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"IMAGENAME.PNG"]]];
You have to put the name of the declared label instead of UILabel
Can text in UILabel have a colorWithPatternImage: assigned to it?
It does use the colorWithPatternImage though
What do you mean by it didn't pan out.
Also this is a possible duplicate of the link I just gave you.
It turns out I had actually implemented it correctly. The line of code I provided above was not an exact line out of my program, but more of a generality.
The reason I was getting a completely black font was that part of the particular image I was using was entirely black. It seems that the image isn't scaled down to fit the text and UILabel so what was being revealed was the bottom 1/5 of the image. I did not have to solve this problem as the image provided for me to implement this was a repetitive pattern throughout the image so that any part of the image would produce the desired effect of a wooden panel type color font.

UIPresentModalViewController view alpha is not being set

I want to present a view controller where I have one Background imageView.
Alpha for that imageview is 0.5 (want to add as semi-transperant black image so). But when I present that view controller that alpha doesn't work for view. That image entirely looks blackish, like alpha has not been even set.
This issue is there for iPad device only.
Please help me out.
Code:
ViewController1.m:
[self presentModalViewController:viewController2];
ViewController2.xib: (in nib I am setting below values no in code)
[self.view setBackgroundColor:[UIColor clearColor]];
[self.bgImageView setAlpha:0.5]; // this image is dark black, i want to display the
content of the screen which is behind this (viewController1.view), kind of semi-transperancy
I tried one more thing, this time i have removed imageView and set uiview bgcolor to black, opaque=NO, alpha=0.2 (in nib itself). So while animation of presenting it looks perfect. But when view has been placed it turns into alpha=1.0 (complete black)
Still there is no transparency where am i wrong over here.
Answer Is Here: There is some bug/limitation with ModalViewController so its better to go with addSubview for such situation
Try to write imageview.alpha = 0.5 after you present the modelviewcontroller and see what happens. Just give it a try.
EDIT:
1)Clean Build and Run
The image alpha you are trying to set, is it in viewcontroller that you are presenting from or is it in modalviewcontroller?
Answer Is Here: There is some bug/limitation with ModalViewController so its better to go with addSubview for such situation

How to change the highlighted color of a tabbaritem?

I am trying to change the highlighted color of the tabBarItem just like the Viber app does. I don't want to change the color of all the Bar, just the highlighted color.
I have read a lot posts here, but none of them explained how to do only this modification.
Does someone know how to do this? There is many apps that have customized colors!
Currently, with iOS4, this type of customization is not possible with a standard UITabBar. Most applications that have customized UITabBars actually create their own. Check out CocoaControls for some drop in third-party solutions you could use.
Have you tried:
UIView *bg = [[[UIView alloc] initWithFrame:CGRectMake(0,0,320,49)] autorelease];
[bg setBackgroundColor:[UIColor redColor]];
[self.tabBarController.tabBar insertSubview:bg atIndex:1];
That code initially creates a background view for the tabBar and sets it's colour to red.

image display in uiscrollview

Am facing a probem with my scrollview.Am displaying the image in a scrollview programatically and i added the zooming and paning effects.When i run the application image is displaying in the scroll view but it is not in centre(like it is displaying at right corner and some part of image is inside the scrollview)After zooming when i scroll the image the image is moving and i can see the black area which i dont want.
Please,somebody can help me
Thanks in advance
here is the code
mainView2 = [[UIScrollView alloc]init];
[mainView2 setFrame:CGRectMake(imageView2.frame.origin.x, imageView2.frame.origin.y, 222, 120)];
[mainView2 setContentSize:CGSizeMake(600,600)];
[mainView2 setMaximumZoomScale:2.0];
[mainView2 addSubview:imageView2];
mainView2.delegate = self;
[self.view addSubview:mainView2];
mainView2.scrollsToTop = NO;
here mainview2 is my scrollview and imageview2 is the uiimageview which i want to display in scrollview
I don't know exactly what you mean "I can see the black Area". However, the "center image" problem is quite a common one. As far as I know, there is no out of the box way to solve this. Fortunately, there is some great code on github which handels image scrolling in a UIScrollView nicely. See this question and this github project for further information.

Is there a way that I can make an overlay view on the iPhone SDK?

I've seen examples of overlay views in different iPhone apps (Skype, Phone.app (while making a call), Google Mobile) and I was wondering how I could do the same in an app.
I'm making an app which has a record button in it and when that button is pressed, I want a nice looking overlay (similar to the overlay view that appears when making a call on the iPhone) that says "Recording" with a count in seconds to appear along with a stop button.
Is there any guide or anything I can look at to help me do this? Thanks.
Also I was wondering how I can make a vertically long view that requires the user to scroll with their finger that isn't a TableView. Also thanks.
I usually just create them myself; it's just a UIView which you insert above your other subviews.
UIView *overlayView = [[UIView alloc] initWithFrame:self.view.frame];
overlayView.backgroundColor = [UIColor blackColor];
overlayView.alpha = 0.4;
[self.view addSubview:overlayView];
[overlayView release];
As for your second question check out UIScrollView's.
For scrolling you need a UIScrollView. Look at the class reference for examples on how to use it.
For my overlays I push a new modal view which I make transparent.