Changing of cell background color have some weird animation. I want to change this color immediately without animation. Maybe I should override setBackgroundColor method in subclass somehow?
cell.backgroundColor = [UIColor redColor];
Probably that you are changing that color while a UIView animation is in progress (a transition, a tableView row update, a UIView animation block, etc).
Try the following:
[UIView performWithoutAnimation:^{
cell.backgroundColor = [UIColor redColor];
}];
UPDATE: I'm not sure what kind of animation you got though. I made a simple test UITableViewController that change the cell color without animation when you tap on them (using what you specified in your comment), and it works.
Related
I am writing an app and I want to make a textfield background turn white.
So far this is my code:
- (void)viewDidLoad
{
UITextField *txtfield = UsernameTextField;
[txtfield setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.5] ];
txtfield.layer.borderColor = [UIColor blackColor].CGColor;
txtfield.layer.borderWidth = 1;
txtfield.borderStyle = UITextBorderStyleRoundedRect;
[super viewDidLoad];
// Do any additional setup after loading the view.
}
But this code have a result like this:
and i tried this code , to increast alpha
[txtfield setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.8] ];
still the same
and also i see this post
iPhone UITextField background color
and i tried
but it still the same
Why textfield wont turn to white?
First thing first you should
[super viewDidLoad] should be the first statement in - (void)viewDidLoad after initialising parent child should do initialise.
Second
Please check the order of views put on view controller bring UsernameTextField to top of all views or you can call [self.view bringSubviewToFront:txtfield] in code
Third
Only by setting alpha to 1.0 you can see complete white background.
and finally is you still don't get it resolved then there is some changes you did in xib/storyboard view. So to reset just delete textfield and add it again.
In order to change background color it's important to set the border to None
txtfield.borderStyle = UITextBorderStyleNone;
Details: Changing background colour within a TextField in Interface Builder
iPhone UITextField background color
From Apple Doc:
When set, the image referred to by this property replaces the standard appearance controlled by the borderStyle property. Background images are drawn in the border rectangle portion of the text field. Images you use for the text field’s background should be able to stretch to fit.
I am setting the view as a subview in UIWindow. It's working fine as such. I am able to load the view and do my work; however, if I actually go and change the background color, in a small area at the bottom the color doesn't change.
This is the code that I am using to add this view as a subview to Window
UIWindow* keyWindow= [[UIApplication sharedApplication] keyWindow];
[keyWindow addSubview: self.view];
This is the code to change the color:
self.view.backgroundcolor =[UIColor bluecolor];
This behaviour happens only in iOS6. In iOS7, the background color changes completely.
#Fogmeister is correct you should add a rootViewController to it, but just replying your question, your view has not the same size of the window, so this small area at the botton is the uiwindow you are seeing behind your view. You can just set the frame of your view with the same size of the window self.view.frame = keyWindow.bounds;
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 was wondering how I actually use background in normal tableview(non grouped). For example take a look at the clock app and the background there. Any ideas?
You can set the background of your table view using the same techniques as the grouped table view (something like self.tableView.backgroundView = anImageView;), but your cells' background are opaque and, therefore, will hide it.
You'll then have to set, in tableView:cellForRowAtIndexPath: the background color of your cells to clearColor [UIColor clearColor] and it's backgroundView to nil.
Run the app now, and there might still be something wrong: the background of the cell's labels is possibly also opaque (I say possibly because the cells might have picked up the cell background color and changed the background color of their subviews accordingly).
If it is the case, once again, in tableView:cellForRowAtIndexPath:, set the subviews's background color to clearColor.
You can also try to set image view with your own image as backgroundView:
UIImage *yourImage = ...
UIImageView *imageView = [[UIImageView alloc] initWithImage:yourImage];
self.tableView.backgroundView = imageView;
[imageView release];
I wanted to put a background image partially visible behind a list view. I created a list view in my nib with an image view behind it and made the list view background 20% opacity. This allows the background image to show thru but my text in the cells show a white background behind and if I create the cells in cellForRowAtIndexPath the cells have a white background too.
I am creating and setting the cell textLabel and the detailTextLabel in the cellForRowAtIndexPath event.
Not sure how to get rid of that, or if there is a better way to do the background image.
I had a similar issue and resolved it by setting the cell.contentView.backgroundColor to [UIColor clearColor] in cellForRowAtIndexPath.
If you did not want to make the whole cell transparent but the labels only, you can set the backgroundColor attribute of the textLabel and detailTextLabel to clear as well:
cell.textLabel.backgroundColor = [UIColor clearColor];
To set the background image of a table at run time rather than in a nib you can create a new UIColor from an image. Like so:
UIImage *img = [UIImage imageWithContentsOfFile: someFilePath]; // get your background image
UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage: img];
[myTable setBackgroundColor: backgroundColor];
[backgroundColor release];