I wanna ask how to set background image while loading ads until it shows the ads.
AdMob = [[GADBannerView alloc]init];
AdMob.frame = CGRectMake(0, 0 , GAD_SIZE_300x250.width, GAD_SIZE_300x250.height);
AdMob.backgroundColor = [UIColor grayColor];
AdMob.adUnitID = [GlobalVariable sharedInstance].PID_IOS_PHONE;
AdMob.rootViewController = self;
GADRequest *request = [GADRequest request];
[AdMob loadRequest:request];
you can set Image as a background using bellow piece of code:-
AdMob.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Background.png"]];
Related
I am working on uiwebview and it is supposed to load dynamic urls coming from the server.
i want to show it fitting to the iPhone screen size in my iPhone application and also it should zoom in and out.
Code i am using for it is:
m_pView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 430)];
m_pView.backgroundColor = [UIColor blackColor];
self.view = m_pView;
UIWebView *aWebView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 1, 320, 400)] autorelease];
aWebView.dataDetectorTypes = UIDataDetectorTypeNone;
aWebView.delegate = self;
NSString* url = [NSString stringWithFormat: #"http://%#",[m_URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
aWebView.scalesPageToFit = YES;
aWebView.autoresizesSubviews = YES;
aWebView.frame = self.view.bounds;
NSURL *aURL = [NSURL URLWithString: url];
NSURLRequest *aRequest = [NSURLRequest requestWithURL:aURL];
//load the index.html file into the web view.
[aWebView loadRequest:aRequest];
[m_pView addSubview:aWebView];
self.m_webView = aWebView;
Please let me know how to achieve webview fitting to the iphone screen size without loosing zoom in/out feature.
Thanks in advance.
Use following code
yourWEbView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
yourWEbView.contentMode = UIViewContentModeScaleAspectFit;
problem might be in this line:
aWebView.frame = self.view.bounds;
Why you're setting bounds of self.view while adding webview to m_pView?
How i can display vertical pages for UITextView in UIScrollview
self.textView = [[[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 410)]autorelease];
self.textView.textColor = [UIColor blackColor];
self.textView.font = [UIFont fontWithName:#"Georgia-Bold" size:14];
self.textView.textAlignment = UITextAlignmentCenter;
//self.textView.backgroundColor = [UIColor colorWithHue:2.0/12 saturation:2.0 brightness:4.0/10 alpha:1.0];
self.textView.backgroundColor = [UIColor whiteColor];
self.textView.editable = NO;
self.textView.delegate = self;
self.textView.textAlignment = UITextAlignmentCenter;
self.textView.layer.borderWidth = 1;
self.textView.layer.borderColor = [[UIColor darkGrayColor] CGColor];
self.textView.layer.cornerRadius = 1;
self.textView.textAlignment = UITextAlignmentCenter;
self.textView.text = #"Juice fasting makes every other natural method work faster...............";
[self.view addSubview:self.textView];
scrollView.contentSize = CGSizeMake(textView.frame.size.width, textView.frame.size.height);
scrollView.maximumZoomScale = 4.0;
scrollView.minimumZoomScale = 0.75;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.delegate = self;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
[self.scrollView addSubview:self.textView];
[button release];
[super viewDidLoad];
}
I have a long text in UITextView. How i can display this UITextView in vertical pages when user scrolls.
Appreciate help.
Did you try paging?
textView.pagingEnabled = YES;
Is that what you want? Otherwise I probably would recommend using a default UILabel in a default UIScrollView, to set this up. (Adding one UILabel per page to the scrollView)
Make the text view large enough so that there is no scrolling within it (or change it to a UILabel), and put that inside a separate scrollView.
Then set
scrollView.pagingEnabled = YES;
and make sure the height of the content size is larger than the height of the actual scroll view. So if the text view is 320x960, make the scroll view 320x480.
I have made an iPad application, in that I used navigation control,
now in the title bar , I want to put image on left side, so I hide title bar with label, but label is not covering entire width of title bar,
IL APP IN THE SCREEN SHOT,
here is the code snippet,
UILabel *titleView = (UILabel *)self.navigationItem.titleView;
if (!titleView) {
titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 800, 50)];
titleView.backgroundColor = [UIColor clearColor];
titleView.font = [UIFont boldSystemFontOfSize:20.0];
titleView.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
titleView.textColor = [UIColor yellowColor]; // Change to desired color
titleView.backgroundColor=[UIColor blackColor];
titleView.text = #"IL APP";
titleView.textAlignment=UITextAlignmentCenter;
//self.navigationItem.titleView = titleView;
[self.navigationItem setTitleView:titleView];
[titleView release];
}
#Gama as far as your question is concerned you are asking to put an Image but your real issue being described is that the label is not covering up the title bar. To cover that properly you can use
UILabel *titleView = (UILabel *)self.navigationItem.titleView;
if (!titleView) {
titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 32)];
titleView.backgroundColor = [UIColor clearColor];
titleView.font = [UIFont boldSystemFontOfSize:20.0];
titleView.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
titleView.textColor = [UIColor yellowColor]; // Change to desired color
//titleView.backgroundColor=[UIColor blackColor];
titleView.text = #"IL APP";
titleView.textAlignment=UITextAlignmentCenter;
[self.navigationItem setTitleView:titleView];
[titleView release];
}
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
For using an image you can use an image view instead of a label to be assigned as the titleView for navigationItem.
Hope it helps
I tried to solved your problem but I get the same result.
But you can hide navigation bar and add the UILabel in to your ViewController
self.navigationController.navigationBarHidden = FALSE;
[self.view addSubview:titleview];
UIImageView *imageNav = [[UIImageView alloc] initWithImage: [UIImage imageNamed: #"navImage.png"]];
[self.navigationController.navigationBar addSubview:imagenav];
[self.navigationController.navigationBar sendSubviewToBack:imageNav];
[imageNav release];
Hi i wanted to do the same thing and i saw your posting, i basically used some of the code you provided and modified it a little and got it to work see below:
//declare and initialize your imageView
UIImageView *titleImage = (UIImageView *)self.navigationItem.titleView;
titleImage = [[UIImageView alloc]
initWithFrame:CGRectMake((self.navigationController.navigationBar.frame.size.width/2)
- (100/2), 0, 100, self.navigationController.navigationBar.frame.size.height)];
//setting the image for UIImageView
titleImage.image = [UIImage imageName:#"photo.jpg"];
//NOTE: you have to do this line at the bottom to add image to the navigation bar Try it it WORKS!
self.navigationItem.titleView = titleImage;
I'am trying to setup a png image as my tableview's background. With the following code all are fine! But only on iPhone Simulator. If I try to run the application on an iPhone device the background of tableview remains white (or clear). Do you thing thing that is something about the way I tried to set the background color. I have been trying many ways until the following, but all have the same issue.
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.opaque = NO;
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"TableViewBackground.png"]];
Thank you in advance!
Please use following code.
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"TableViewBackground.png"]];
[tempImageView setFrame:self.tableView.frame];
self.tableView.backgroundView = tempImageView;
[tempImageView release];
Thanks,
I think this approach cleaner:
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"TableBackground.jpg"]];
self.tableView.backgroundColor = background;
[background release];
Simple swift version will be
let tempImageView = UIImageView(image: UIImage(named: "yourImage"))
tempImageView.frame = self.tableView.frame
self.tableView.backgroundView = tempImageView;
Is your image actually named TableViewBackground.PNG (note the capitals)? You need to have the case match exactly on an iOS device, whereas it doesn't need to match exactly in the Simulator.
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"TableViewBackground.png"]];
[tempImageView setFrame:self.tableView.frame];
self.tableView.backgroundView = tempImageView;
[tempImageView release];
This works perfect. Thanks to Ravin by Jona
An IBDesignable tableview subclass that will let you attach an image from interface builder
import UIKit
#IBDesignable
class DesignableTableView: UITableView {
#IBInspectable var backgroundImage: UIImage? {
didSet {
if let image = backgroundImage {
let backgroundImage = UIImageView(image: image)
backgroundImage.contentMode = UIViewContentMode.ScaleToFill
backgroundImage.clipsToBounds = false
self.backgroundView = backgroundImage
}
}
}
}
[TableView setBackgroundView:nil];
[TableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"apple.png"]] ];
This works perfectly fine, also if you want to use a pattern image for your background.
UIImage *image = [UIImage imageNamed:#"something.png"];
self.tableView.backgroundView = nil;
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
A little late but maybe for all the others looking for a solution. I could get that work by using the following code 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.
Objective-c version:
cell.backgroundColor = [UIColor clearColor];
Also see this:
How to create a UITableViewCell with a transparent background
Thanks #Ravin for your answer.
In Swift 5.0:
let tempImageView = UIImageView(image: UIImage(named: "justin_bieber_topless.png"))
tempImageView.frame = self.tableView.frame
self.tableView.backgroundView = tempImageView;
UIImageView *imageviewTemp = [[UIImageView alloc] init];
[(UIImageView *)imageviewTemp sd_setImageWithURL:[NSURL URLWithString:self.stringOfPassedImage]];
[imageviewTemp setFrame:self.tableView.frame];
self.tableView.backgroundView = imageviewTemp;
I want to add a custom UIImageView to UISearchDisplayController's table view background and set table view's background color to clearColor. Tried a few different approach but couldn't find the right solution. Any idea how to approach this?
Note: I don't want to add to searchDisplayController's searchResultsTableView's view hierarchy, but rather overlay another sibling view below it)
You can set the background image in a similar way you would for your main table, only set it in the searchDisplayControllerDidBeginSearch delegate method. For instance:-
- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
[controller.searchResultsTableView setDelegate:self];
UIImageView *anImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"gradientBackground.png"]];
controller.searchResultsTableView.backgroundView = anImage;
[anImage release];
controller.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
controller.searchResultsTableView.backgroundColor = [UIColor clearColor]; }
You can also do this wherever you instantiate your UISearchDisplayController. In my app I was doing this in my UITableView viewDidLoad method and was matching the styles between the two tables:
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.separatorColor = [UIColor blackColor];
self.tableView.backgroundColor = [UIColor grayColor];
self.tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;
searchController.searchResultsTableView.separatorColor = self.tableView.separatorColor;
searchController.searchResultsTableView.backgroundColor = self.tableView.backgroundColor;
searchController.searchResultsTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
}