UITableView's subview not showing - ios

I have a UITableViewController subclass. When I try to add a subView its not showing.
The subView is a UIImageView, I made a custom loading view (its shown when user is loading data from web).
But when I add,
[self.tableView addSubview:spinner];
[spinner startAnimating];
The spinner is not showing. What am I missing or I did wrong?
EDIT
Code of spinner
UIImageView *spinner = [[UIImageView alloc]init];
spinner.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"spin8.png"],
[UIImage imageNamed:#"spin7.png"],
[UIImage imageNamed:#"spin6.png"],
[UIImage imageNamed:#"spin5.png"],
[UIImage imageNamed:#"spin4.png"],
[UIImage imageNamed:#"spin3.png"],
[UIImage imageNamed:#"spin2.png"],
[UIImage imageNamed:#"spin1.png"],
nil];

Use MBProgress HUD
Its an custom control through which you can easily add various type of Loading indicator
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeAnnularDeterminate;
hud.labelText = #"Loading";
[self doSomethingInBackgroundWithProgressCallback:^(float progress) {
hud.progress = progress;
} completionCallback:^{
[hud hide:YES];
}];
Use above code or there are lot of other options as well

Try this
CGRect spinnerFrame = //frame of spinner
UIImageView *spinner = [[UIImageView alloc] initWithFrame:spinnerFrame];
spinner.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"spin8.png"],
[UIImage imageNamed:#"spin7.png"],
[UIImage imageNamed:#"spin6.png"],
[UIImage imageNamed:#"spin5.png"],
[UIImage imageNamed:#"spin4.png"],
[UIImage imageNamed:#"spin3.png"],
[UIImage imageNamed:#"spin2.png"],
[UIImage imageNamed:#"spin1.png"],
nil];
[self.tableView addSubview:spinner];
[spinner startAnimating];

Try adding it to the tableView's contentView:
[self.tableVew.contentView addSubview:spinner];

Related

UIImage animatedImageNamed repeat count

I have a images sequence animated with :
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 120)];
[UIImage animatedImageNamed:#"spinner-" duration:1.0f];
imgView.contentMode = UIViewContentModeCenter;
imgView.animationRepeatCount = 1; // No effect
[self.view addSubView:imgView];
But the sequence keeps looping. Is there a way to control the repeat count (and keep displaying the last image) ?
In your case, using [UIImage animatedImageNamed:#"spinner-" duration:1.0f]; won't give you what you want.
For what you would like to achieve, I would recommend using UIImageView.
Usage:
First create an UIImageView object:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:<FRAME_SIZE>];
Second, create an array that holds your images to be animated.
If you just have a few, do the following:
NSMutableArray *animatedImagesArray = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:#"spinner-1.png"], [UIImage imageNamed:#"spinner-2.png"], nil];
If you have more, then you could load your images into the array like this:
for (int i = 0; i < <NUM_OF_IMAGE_COUNT>; i++)
{
[animatedImagesArray addObject:[UIImage imageNamed:[NSString stringWithFormat:#"spinner-%d%#", i, #".png"]]];
}
Once all that is done, then we configure the controls you want:
imageView.animationImages = animatedImagesArray;
imageView.animationDuration = 1.0f;
imageView.animationRepeatCount = 1.0f;
Then start animating it by:
[imageView startAnimating];
And stop the animation via:
[imageView stopAnimating];
If you would like the UIImageView to hold the last image after stopping, we would need to carry out the following before starting the animation:
imageView.image = [imageView.animationImages lastObject];
....
[imageView startAnimating];
Hope this helps.
You set the repeat count in the UIImageView object that displays your image.
UIImage *testImage = [UIImage animatedImageNamed:#"Box.jpg" duration:1.0f];
UIImageView *imgView = [[UIImageView alloc] initWithImage:testImage];
[imgView setAnimationRepeatCount:1];

UIButton with Animation Image doesn't showing

I have found posts that concern with UIButton with Animation Image.
However i didn't found any solutions.
Here is my code.
UIImage *imageOne=[UIImage imageNamed:#"1Ads.png"];
UIImage *imageTwo=[UIImage imageNamed:#"2Ads.png"];
UIImage *imageThree=[UIImage imageNamed:#"3Ads.png"];
NSArray *arr = [[NSArray alloc] initWithObjects:imageOne,imageTwo,imageThree, nil];
self.btnAds.imageView.animationDuration = 7.0;
self.btnAds.imageView.animationImages = arr;
[self.btnAds.imageView startAnimating];
It's doesn't showing anything in View.
How can i do it?
Use the imageView property of UIButton. You can create an animation like this:
[myButton setImage:[UIImage imageNamed:#"1.png"] forState:UIControlStateNormal];
myButton.imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"1.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
[UIImage imageNamed:#"4.png"],
[UIImage imageNamed:#"5.png"],
nil];
myButton.imageView.animationDuration = 0.5;
[myButton.imageView startAnimating];

Activity Indicator is not showing on images

Hi I'm trying to upload image's from iphone to server in that i given activity indicator for the user to known that image is uploading while clicking upload it will show activity indicator for few minutes.
But my problem is the activity indicator only showing in few images its not showup on all the images pls tell me how to resolve this.
my activity coding .
-(void)temp{
spinner = [[UIActivityIndicatorView alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
//spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:]
spinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
[spinner setCenter:CGPointMake(160, 240)]; // (mid of screen) I do this because I'm in landscape mode
[self.view addSubview:spinner];
spinner.color = [UIColor blackColor];
spinner.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.4];
[spinner startAnimating];
[spinner release];
}
-(void) myMethod{
[spinner stopAnimating];
spinner.hidden = YES;
spinner.color = [UIColor yellowColor];
}
- (IBAction)pushUpload:(id)sender {
[self temp];
[self performSelector:#selector(myMethod) withObject:nil afterDelay:5.0f];
}
Instead of ActivityIndicator use AsynchronousImageView It will automatically add activityindicator while loading an image.
[AsynObj loadImageFromURL:[NSURL URLWithString:ImageUrl]];
You can get the AsyncImageView classes from the following link https://github.com/nicklockwood/AsyncImageView
I hope it will help!

Customizing UISearch bar

I am trying to customize my search bar like this
So far I have managed to do upto this
Now I need to know how to add image on right side, shaping the corners and changing background to an image. This is my code so far. I can do this with help of UITextField but I want to do this using the UISearchBar. Any help??
- (void)setSearchIconToFavicon
{
// commented are the things I tried out
UITextField *searchField = nil;
for (UIView *subview in searchBar.subviews)
{
if ([subview isKindOfClass:[UITextField class]])
{
searchField = (UITextField *)subview;
break;
}
}
if (searchField)
{
UIImage *image = [UIImage imageNamed: #"search_btn.png"];
UIImageView *iView = [[UIImageView alloc] initWithImage:image];
//UIImage *image2 = [UIImage imageNamed: #"search_next_btn.png"];
//UIImageView *iView2 = [[UIImageView alloc] initWithImage:image2];
searchField.leftView = iView;
//searchField.rightView=iView2;
[[self.searchBar.subviews objectAtIndex:0] removeFromSuperview];
searchField.textColor = [UIColor grayColor];
}
}
You can replace the Bookmark image instead, and adjust its offset if necessary.Like this..
[self.searchDisplayController.searchBar setImage:[UIImage imageNamed:#"yourImage"] forSearchBarIcon:UISearchBarIconBookmark state:UIControlStateNormal];
[self.searchDisplayController.searchBar setPositionAdjustment:UIOffsetMake(0, 0) forSearchBarIcon:UISearchBarIconBookmark];
And you can handle the button event in the delegate method:
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar
i Hope you got my point.
You can this line of code if your target application is >=5.0 to change background image of search bar.
[[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:#"searchbar.png"]forState:UIControlStateNormal];

How to add UIImages like animation using NSTimer?

I want to add a array of UIImages to UIImageView using NSTimer. Such that it will be like an animation. How to do it in iOS?
Thanks in advance.
There is a very simple way to do it.
// create the view that will execute our animation
UIImageView* campFireView = [[UIImageView alloc] initWithFrame:self.view.frame];
// load all the frames of our animation
campFireView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"campFire01.gif"],
[UIImage imageNamed:#"campFire02.gif"],
[UIImage imageNamed:#"campFire03.gif"],
[UIImage imageNamed:#"campFire04.gif"],
[UIImage imageNamed:#"campFire05.gif"],
[UIImage imageNamed:#"campFire06.gif"],
[UIImage imageNamed:#"campFire07.gif"],
[UIImage imageNamed:#"campFire08.gif"],
[UIImage imageNamed:#"campFire09.gif"],
[UIImage imageNamed:#"campFire10.gif"],
[UIImage imageNamed:#"campFire11.gif"],
[UIImage imageNamed:#"campFire12.gif"],
[UIImage imageNamed:#"campFire13.gif"],
[UIImage imageNamed:#"campFire14.gif"],
[UIImage imageNamed:#"campFire15.gif"],
[UIImage imageNamed:#"campFire16.gif"],
[UIImage imageNamed:#"campFire17.gif"], nil];
// all frames will execute in 1.75 seconds
campFireView.animationDuration = 1.75;
// repeat the annimation forever
campFireView.animationRepeatCount = 0;
// start animating
[campFireView startAnimating];
// add the animation view to the main window
[self.view addSubview:campFireView];
Source: http://web.archive.org/web/20120305060003/http://appsamuck.com/day2.html

Resources