UIDate Picker background color [duplicate] - iphone

This question already has answers here:
How to change UIPicker Color ? iPhone
(6 answers)
Closed 8 years ago.
HI I would like to change the background color of the UIDatePicker from the current glossy image to clear just like in this example
(source: apple.com)
Any ideas how to do that? I tried
datepicker.backgroundColor = [UIColor clearColor];
but it didnt work.

UIDatePicker contains one subview. That subview, in turn, contains 15 other subviews that form UIDatePicker's appearance. The first and the last of them are the background, so to make it transparent just turn them off and set background color of main subview to clearColor:
// create the picker
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 320, 320)];
// add it to some view first
[actionSheet addSubview:datePicker];
[datePicker release];
// clear the background of the main subview
UIView *view = [[datePicker subviews] objectAtIndex:0];
[view setBackgroundColor:[UIColor clearColor]];
// hide the first and the last subviews
[[[view subviews] objectAtIndex:0] setHidden:YES];
[[[view subviews] lastObject] setHidden:YES];

Related

How to set the cursor staring position in UITextField [duplicate]

This question already has answers here:
UITextField set cursor to start text position
(3 answers)
Closed 9 years ago.
I am developing one application.In that i set the text filed border width as 1o base don my requirement.So now the first character of text filed will be hidden by border color.SO please tell me how can i set the cursor staring position for UITextField.
add UIview with border and add UITextField inside UIView
UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0,0, frame.size.width, frame.size.height)];
[baseView setBackgroundColor:[UIColor clearColor]];
[baseView setUserInteractionEnabled:YES];
[baseView setClipsToBounds:NO];
baseView.layer.borderColor =[UIColor lightGrayColor].CGColor;// UIColorFromRGB(0Xcccccc).CGColor;
baseView.layer.borderWidth = 1.0f;
[self addSubview:baseView];
UITextField* txtField = [[UITextField alloc]initWithFrame:CGRectMake(1, 1, frame.size.width-2, frame.size.height-2)];
[txtField setBackgroundColor:[UIColor whiteColor]];
[baseView addSubview:txtField];
Make a subclass of UITextField and use that.
Override these methods in your subclass. They will add space from left side in your textfield.
// placeholder text reposition
- (CGRect)textRectForBounds:(CGRect)bounds {
return CGRectInset(bounds, 10, 0);
}
// text reposition
- (CGRect)editingRectForBounds:(CGRect)bounds {
return CGRectInset(bounds, 10, 0);
}

Is it possible to remove UISearchBar's tint image?

i have to hide searchbar tint.
i write foll0wing code
UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 15, 270, 15)];
searchBar.delegate = self;
searchBar.barStyle = UISegmentedControlStylePlain;
searchBar.placeholder =#"search";
searchBar.tintColor=[UIColor clearColor];
[imageview addSubview:searchBar];
here search bar add on imageview. i want to hide tint side but bydeaflt it comes .i also chage the color to tint color but it not work.is anybody have idea of removing or hide tint on searchbar .Thanks
Hope this helps.
[searchBar setBackgroundImage:[UIImage new]];
Will also work in iOS 7.1
I have used this code. It completely removed the tint around the search text bar.
for (id v in [self.search subviews]) {
if (![v isKindOfClass:NSClassFromString(#"UISearchBarTextField")]) {
[v setAlpha:0.0f];
[v setHidden:YES];
}
else {
[v setBackgroundColor:[UIColor clearColor]];
}
}
Here's how I customized the UISearchBar
if ([[[searchBar subviews] objectAtIndex:0] isKindOfClass:[UIImageView class]]){
[[[searchBar subviews] objectAtIndex:0] removeFromSuperview];
}
This removes the background bar style.
You can then add any custom subview you want.
Try this
[searchBar setTranslucent:YES];
Also, don't set the tintColor when using translucent

UITableview background view colour -iphone

I have an UITableview controller without an XIB.
I set the background colour of the tableview by doing this:
[self.tableView setBackgroundColor:[UIColor colorWithPatternImage:
[UIImage imageNamed:#"MmyImage.png"]]];
My image is a gradient image, so eventhough the above code is ok, it redraws the image for each cell when the tableview goes to edit view, and it appears as lines which is not looking elegant.
I would like to set the tableviews background to clear colour and set the superview's colour to the image, so that the tableview transitions smoothly over the superview. However the below code does not work:
[self.view setBackgroundColor:[UIColor colorWithPatternImage:
[UIImage imageNamed:#"myImage.png"]]];
[self.tableView setBackgroundColor:[UIColor clearColor]];
This makes the background completely white, I dont know why.
Help appreciated..thanks.
Edited:new code but this does not work as well:
UIImageView * imgBg = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:#"myImage.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:6]];
imgBg.frame = self.tableView.window.bounds;
[self.tableView.superview addSubview:imgBg];
//[self.view addSubview:imgBg];
//[self.tableView.window sendSubviewToBack:imgBg];
//[self.view bringSubviewToFront:self.tableView];
[self.tableView setBackgroundColor:[UIColor clearColor]];
[imgBg release];
In a custom UITableViewController subclass, self.view will return the same as self.tableView. So what you're doing there is altering the same object. In the end, you get to see the UIWindow. So to get the desired result, you should do this –
[self.view.window setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"myImage.png"]]];
[self.tableView setBackgroundColor:[UIColor clearColor]];
UITableView has a backgroundView property. Use it.
aTableView.backgroundView = [[[UIView alloc] initWithFrame:aTableView.bounds] autorelease];
aTableView.backgroundView.backgroundColor = backgroundColor;
First in your xib file, add a parent view. add table view in that parent view. set parent view's background color to your desired background. then set your tableview's background color to [UIColor clearColor].
Check also, if your table view is a group table style or not? if it is group table style, then the cell have distinct background. Then you need to clear the background of each cell. The best way to do is,
create a blank UIView *bkview = [[UIView alloc] initWithRect:CGRect(0,0)];
set this
as your cells background view.
I hope this will work.
then your second code will be right, except:
[self.view setBackgroundColor:[UIColor colorWithPatternImage:
[UIImage imageNamed:#"myImage.png"]]];
replace this:
UIImageView * imgBg = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:#"myImage.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:6]];
imgBg.frame = self.view.bounds;
[self.view addSubview:imgBg];
[self.view sendSubviewToBack:imgBg];
Edit
I think:
[self.tableView setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0]]; will helps, that is the only difference now.

Best Practice to Float a View over Another View?

I have a 320x460 view with a number of buttons, depending on the button pressed, a 280x280 view pops up over the 320x460 view (similar to the behavior of the UIAlertView) using code like this:
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(20, 200, 280, 280)];
overlayView.backgroundColor = [UIColor whiteColor];
[overlayView autorelease];
[overlayView addSubview:label]; // label declared elsewhere
[overlayView addSubview:backgroundImage]; // backgroundImage declared elsewhere
//... Add a bunch of other controls
[label release];
[backgroundImage release];
//... Release a bunch of other controls
[self.view addSubview:overlayView];
Everything works fine displaying the overlayView and all its controls.
The question I have is, how do I get rid of the overlayView once it's displayed? I want to make it not only not visible but to remove it completely, since the user will be popping up the overlayView repeatedly during use.
You need access to overlayView to remove it, I'd suggest adding this to the create side:
overlayView.tag = 5; // Or some other non-zero number
Then later you can use it like this:
-(void)removeOverlayView
{
UIView *overlayView = [self.view viewWithTag:5];
[overlayView removeFromSuperview];
}

How to enable UISearchBar grey out view?

I am using a UISearchBar and once the user taps the bar (and the keyboard pops up) I want the everything besides the keyboard and UISearchBar to be greyed out. Similar to safari when the search is selected. I do not need past searches. See here:
Anyone have any ideas? I've looked through the questions here on StackOverflow and I can't find anything specific.
Thanks!
You can create a UIView that contains the UISearchBar. And then you can set UIView's backgroundColor to get the gray background.
And here's some sample code:
UIView *view1 = [[UIView alloc] init];
view1.frame = CGRectMake(0, 20, 320, 460);
view1.backgroundColor = [UIColor grayColor];
UISearchBar *searchBar = [[UISearchBar alloc] init];
searchBar.frame = CGRectMake(0, 0, 320, 50);
[view1 addSubview:searchBar];
[searchBar release];
[self.window addSubview:view1];
[view1 release];