How to show Background image in UITableView Like
Please help me out. Thank you
Use this
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"cloud.png"] ];
self.tableView.backgroundView = imageView;
[imageView release];
self.tableView.backgroundColor = [UIColor clearColor];
Add an UIImageView to the View, ontop of that place the UITableView and set the background color to clearcolor.
You can also go ahead and set the background color directly:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"image.jpg"]];
Related
After a lot of search I am posting this Question, I have to place an image at the bottom of a UITextfield, I have tried it with the following code :
letterField.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
letterField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
letterField.textAlignment = UITextAlignmentCenter;
letterField.borderStyle = UITextBorderStyleNone;
UIImageView *myView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"text_line.png"]];
[letterField setLeftView:myView];
[letterField setRightViewMode:UITextFieldViewModeAlways];
[myView release];
// letterField.background = [UIImage imageNamed:#"text_line.png"];
// [letterField setBackground:[UIImage imageNamed:#"text_line.png"]];
letterField.textColor = [UIColor whiteColor];
letterField.returnKeyType = UIReturnKeyDone;
[yourtextfield insertSubview:imgViewTitleBackGround atIndex:0];// mgViewTitleBackGround is image view with background image.
//Or
[yourtextfield setBackground:[UIImage imageNamed:#"text_line.png"]];// you can add your image
yourtextfield.textColor = [UIColor redColor];
Hope, this will help you..enjoy
Sorry, my previous answer was totally wrong. From what I can see your image is text_line.png - i suppose it's some kind of separator line, what can i suggest you to try is create a new UIView with the bounds of the UITextField, then add the text field inside this view and add the UIImage view again as subview of this view centering it properly. I don't know if this will fit your needs, but you can give it a try.
I am following the tutorial about a quick dialog box to create a form as below
Now, I would like to change the background of this form. Does anybody know how to achieve this, please advice me on this.
Thanks
Try this, if you want to show an image as a background:
tableView.backgroundColor = [UIColor colorWithPattern:#"your_image_here"];
or
tableView.backgroundColor = [UIColor colorWithRed:128 green:128 blue:128 alpha:1.0];
If this does not work, you can set the backgroundView property of the table view:
tableView.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"your_image_here"]]] autorelease];
Use the backgroundView property of the UITableView.
If you want to use an image, just create a UIImageView and set backgroundView to it.
UIImage *myImage = [UIImage imageNamed:#"foo.png"];
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:myImage];
You may also use the contentMode to adjust how the image fits in the view.
self.tableView.backgroundView.contentMode = UIViewContentModeScaleAspectFill;
You could try some of the properties that UITableView either inherits or declares:
#property(nonatomic, readwrite, retain) UIView *backgroundView
#property(nonatomic, copy) UIColor *backgroundColor
The first is probably what you are going to want. It is declared by UITableView. The second is inherited from UIView.
If you're setting a background colour try this...
tableView.backgroundView = nil;
tableView.backgroundColor = [UIColor redColor]; //replace with your colour
But if you want a pattern image don't use that method... Do this..
tableView.backgroundColor = [UIColor clearColor];
UIView *v = [[UIView alloc] init]; //needs memory Managment (arc example)
v.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"pattern.png"]];
tableView.backgroundView = v;
This is because if the UITableView is group styled the and you have a patterned background image as the tableviews backgroundColor then it's applied to the edges of the cells too but as they're separate views the pattern becomes incorrect.
Hope it helps.
Try to set the background color of the table view; it may require that you change the table view style from grouped to plain.
I am doing the following to set the background image:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImageimageNamed:#"appback_new.png"]];
[self.tableView setBackgroundView:imageView];
in view did load method. Also, I made sure that the background color is set to clear color in story board.
But when the view loads, it loads with a black color.
Did any one face this issue and knows how to resolve it?
Thanks.
Try this it should work :
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"appback_new.png"]];
self.tableView.backgroundColor = background;
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"appback_new.png"]];
try your code after inserting this line of code
tableView.backgroundColor = [UIColor clearColor];
I've added custom background image to my UITableView and it shows fine. Than, i removed any background color from the cells. Now i expect to see only cells' text on top of table's background image, however i see strange behaviour. Cells take pattern color of table's background image, so that i see waves like in the picture:
The background image shell look like this:
*pay attention to white circles that disappear under the cells!
My code is as follws:
in viewDidLoad i set the background image of table view:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"general_bg.png"]];
For each cell i remove any background color like this:
UIView *bckView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
bckView.backgroundColor = [UIColor clearColor];
cell.backgroundView = bckView;
cell.backgoundColor = [UIColor clearColor];
cell.contentView.backgroundColor = [UIColor clearColor];
UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,y,x1,y1)];
textLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:textLabel];
line separators are custom images added to cells.
Instead of setting the BackgroundColor attribute of the tableview, try setting the backgroundview:
UIView *background = [[UIView alloc] initWithFrame:self.tableView.bounds];
background.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"YOUR_IMAGE.png"]];
self.tableView.backgroundView = background;
This should fix the issue of the cell's taking on the same image as the background.
self.tableView.backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"YOUR_IMAGE.png"]];
maybe this is what you're looking for
I'm building an iPhone app without the use of Interface Builder. I have set the background of a grouped UITableView in the following manor:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"groupedBackground.png"]];
I'm trying to fix this background image so that it doesn't scroll with the table cells. Does anyone know how to do this?
We find that it works exactly as you ask, if instead of using backgroundColor, you assign to backgroundView, like so:
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:#"background.png"]];
The table cells then scroll on top of the background, which is stationary. (This has been available since version 3.2 of the SDK, I believe.)
You can achieve a stationary background using a pattern image as follows:
UIView *patternView = [[UIView alloc] initWithFrame:tableView.frame];
patternView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"groupedBackground.png"]];
patternView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
tableView.backgroundView = patternView;
A little late but maybe for all the others looking for a solution. I could get that work by calling the parentViewController in the viewDidLoad method of the UITableViewController:
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
self.tableView.backgroundColor = [UIColor clearColor];
or with using just a background color:
self.parentViewController.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
self.tableView.backgroundColor = [UIColor clearColor];
It took me a while to figure that out but now it works like a charm.
You can place an additional view below UITableView and set its background, so if UITableView is transparent - you'll achieve your goal - it will have correct background and it will not scroll.
use this below code in swift 3.0 to achieve constant background for tableview
self.tableView.backgroundView = UIImageView(image: UIImage(named: "background.png")!)