I added a rightBarButton and I'd like to have that button hide the TableView and show my UIWebView, but I am not seeing the web view.
UITableViewController
viewDidLoad:
mWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 380)];
[mWebView loadHTMLString:#"<html><body>Testing</body></html>" baseURL:nil];
mWebView.hidden=YES;
[self.view addSubview:mWebView];
onButton:
mWebView.hidden = NO;
self.tableView.hidden=YES;
The tableView disappears, but all I get is a white screen instead of the expected 'Testing'
You may need to add [mWebView setNeedsDisplay] and possibly [self.tableView setNeedsDisplay].
Try [webview setBackGroundColor: [UIColor clearColor]];
and [webview setOpaque: NO];
Related
I have a full screen UIScrollView to display my image. An UIActivityIndicatorView is added to the UIScrollView, it spinning well, but how could i make it always spinning in the middle of the screen while I am scrolling, zooming, rotating?
If you add the UIActivityIndicatorView directly to the scroll view it will scroll with the scroll view. But, if you add it to the parent of the scroll view it will remain where it was placed. So, the solution is to add it to the parent of the scroll view.
Notes:
I would recommend having a UIViewController in your window, and then adding these both to the UIViewController.
See the discussion here about adding views directly to your window:
View Controller being sent a message even though it has been deallocated
In ur .h file
UIView *primaryImage;
UIView *secondaryImage;
UIActivityIndicatorView *indicator;
In ur .m file
-(void)indicatorView
{
primaryImage = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
primaryImage.backgroundColor = [UIColor blackColor];
primaryImage.alpha =0.5;
//[self.view.superview insertSubview:primaryImage aboveSubview:self.view.superview];
//[theTableView addSubview:primaryImage];
[self.view addSubview:primaryImage];
secondaryImage = [[UIView alloc] initWithFrame:CGRectMake(127.50,215,65,50)];
secondaryImage.backgroundColor = [UIColor blackColor];
secondaryImage.alpha = 0.9;
secondaryImage.layer.cornerRadius = 12;
[primaryImage addSubview:secondaryImage];
indicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(30, 25, 25, 25)];
indicator.center = CGPointMake(32, 25);
//[indicator hidesWhenStopped];
[indicator startAnimating];
[secondaryImage addSubview:indicator];
}
-(void)dismissCoverImageView {
[indicator stopAnimating];
[indicator removeFromSuperview];
[secondaryImage removeFromSuperview];
[primaryImage removeFromSuperview];
}
and after that you can call [self indicatorView];
and [self dismissCoverImageView];
Define the UIScrollViewDelegate of your UIScrollView. And in the delegate method –(void)scrollViewDidScroll:(UIScrollView *)scrollView change the frame of UIActivityIndicator object.
I have created a UIView through code and want to add some images and description on that view.For that purpose i wished to add a scroll view so that we can user can scroll down to see the images and description.Can anyone help me how to add a scroll view above a UIView through code.Thanks in advance.
Hi try this:-
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
scrollView.backgroundColor=[UIColor clearColor];
scrollView.showsHorizontalScrollIndicator = NO;
[scrollView setDelegate:self];
[scrollView setShowsVerticalScrollIndicator:NO];
[scrollView setShowsHorizontalScrollIndicator:NO];
[[self view] addSubview:scrollView];
Now set the content size of scroll view:-
scrollView.contentSize = CGSizeMake(320, 600);//put values according to your requirements.
UIScrollView *newView = [[UIScrollView alloc] initWithFrame:scrollFrame];
[newView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[newView setDelegate:self];
[newView setBackgroundColor:backgroundColor];
[newView setPagingEnabled:YES];
[newView setShowsVerticalScrollIndicator:NO];
[newView setShowsHorizontalScrollIndicator:NO];
[[self view] addSubview:newView];
you can set Frame In place of scrollFrame.
cheers
Actually you probably don't want to create a UIView, you should create a UIScrollView then add the images and that as subviews of the UIScrollView. Then you'll have everything scrolling. You'll then set up the UIScrollView the way you want it to be.
I am using the code posted below to add Search bar to Navigation bar.
I am getting everything to show up correctly but there is a background (mostly of the UIBarButtonItem that I am not able to get rid of). - Please check the screenshot for iPad.
Is there a way to get rid of blue backgorund showing behind the search bar?
Thanks
Dev.
- (void) viewDidLoad {
[super viewDidLoad];
UIView *hackView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 250, 30)];
hackView.backgroundColor = [UIColor clearColor];
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 250, 30)];
//[searchBar sizeToFit];
[searchBar setBackgroundColor:[UIColor clearColor]];
[hackView addSubview:searchBar];
[searchBar release];
UIBarButtonItem *hackItem = [[UIBarButtonItem alloc] initWithCustomView:hackView];
[hackItem setWidth:250];
self.navigationItem.rightBarButtonItem = hackItem;
[hackView release];
[hackItem release];
}
I believe the problem is that you are adding that extra UIView. Even though it has clearColor background, it is capturing that CGRect created for the UIView *hackView. Get rid of it and simply add the UISearchBar to the UIBarButtonItem and it should solve the display issue.
Also, don't forget to implement the UISearchBarDelegate for proper functionality.
I have solved this problem using following code.
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];
UIBarButtonItem *navRight = [[UIBarButtonItem alloc] initWithCustomView:searchBar];
[[self navigationItem] setRightBarButtonItem:navRight];
[searchBar release];
[navRight release];
I'm creating a horizontal scrolling tableview containing images. I have the swiping functionality working great, and am able to add the images to the scrollView as so in cellForRowAtIndexPath:
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, tv.frame.size.width, 78)];
[scrollView setContentSize:CGSizeMake(700, 78)];
UIImage *footImage = [UIImage imageNamed:#"Foot.png"];
UIImageView *footImageView = [[UIImageView alloc] initWithImage:footImage];
footImageView.frame = CGRectMake(0, 0, 80, 78);
footImageView.userInteractionEnabled = YES;
[scrollView addSubview: footImageView];
UIImage *handImage = [UIImage imageNamed:#"Hand.png"];
UIImageView *handImageView = [[UIImageView alloc] initWithImage:handImage];
handImageView.frame = CGRectMake(90, 0, 80, 78);
handImageView.userInteractionEnabled = YES;
[scrollView addSubview: handImageView];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(highlightImage)];
[scrollView addGestureRecognizer:tapGesture];
NSLog(#"tapGesture added to scrollView");
[[cell contentView] addSubview:scrollView];
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 50, tv.frame.size.width, 50)];
[pageControl setNumberOfPages:4];
[[cell contentView] addSubview:pageControl];
My tapGesture is registering with the selector, hightlightImage, and just logging that its calling this method correctly.
- (void) highlightImage
{
NSLog(#"tapping tapping");
}
What I REALLY am working for is the ability to highlight/select these images if tapped, and highlight/deselect them if tapped again. I will have another button on screen that will navigate to the next page (irrelevant here).
Am I going down the right path here? Obviously I will populate an NSArray of UIImages and populate the scrollView that way, but just spiking it out for now. If someone could give me some direction or an example of how to make each button separately selectable/de-selectable, that would be GREAT:)
Use UIButton instead of UIImageView.
It's got built-in selected functionality.
get rid of your gestures and add highlightImage as the action to every button.
make your highlightImage into highlightImage:(id)sender
sender should be a button so you can just do
[sender setSelected:YES];
How do I change the black/gray color to white?
This is just a simple view with a UIView attached to the UIViewControllers property together a with a webview that fills the UIView.
UPDATE
Here's the code that works:
- (void)loadView {
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 416.0f)];
[webView setBackgroundColor:[UIColor whiteColor]];
self.view = webView;
[webview release];
}
Thanks in advance.
You can use the UIScrollView's backgroundColor property to achieve this, the signature being:
#property(nonatomic, copy) UIColor *backgroundColor
As such to change it to white, you'd use:
[myScrollView setBackgroundColor:[UIColor whiteColor]];
A few improvements for your code:
- (void)viewDidLoad {
[super viewDidLoad];
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(self.view.bounds)];
[webView setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview: webView];
[webview release], webview = nil;
}
Overall you should find this approach less brittle.
PS. If you keep a reference to the UIWebView around, don't forget to release it in - viewDidUnload.