How can I set color of bottom view with all elements of UIActivityViewController?
My current implementation changes color for all view -
CopyLink *copyLink = [[CopyLink alloc]init];
copyLink.delegate = self;
self = [self initWithActivityItems:#[emailActivity] applicationActivities:#[copyLink]];
self.view.backgroundColor = [UIColor redColor];
self.completionHandler = ^(NSString *activityType, BOOL completed)
You can't do this, the UIActivityViewController is supposed to take form of an overlay sheet, I doubt you can even access the view of it let alone its background colour, You may have to create a custom Subview and then use that as the subview
Here is the best way to use UIActivityViewController :
-(void)doStartStopSpinner
{
if (![spinner isAnimating])
{
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
spinner.center = self.view.center;
spinner.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.6];
[self.view addSubview:spinner];
[spinner startAnimating];
}
else
{
[spinner stopAnimating];
[spinner removeFromSuperview];
[viewUpgradePro removeFromSuperview];
}
}
Hope it'll help.
Related
I have a "scroll to load more" behavior on my UITableView. It starts loading more content when you scroll to the bottom. What I want to achieve is to show a UIActivityIndicatorView at the bottom of the UITableView when service call is in progress, and hide it when new items are added.
What is a good way to solve this problem? I am using Swift but objective-C solutions are also welcome.
I have implemented the same functionality in objective-C
In the cellForRowAtIndexPath
if (indexPath.row == [self.yourArrayData count] - 1)
{
// Call the API
[self loadMoreData:#"all" andPages:[NSString stringWithFormat:#"%ld", (long)pages] AndIsLoadMore:YES];
}
Add loader or design
-(void)addLoaderViewAtBottom {
viewLoader = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-100, self.view.frame.size.width, 50)];
[viewLoader setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview:viewLoader];
UIActivityIndicatorView *activityIndicator1 = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator1.center = CGPointMake((SCREEN_SIZE.width/2), 30);
activityIndicator1.alpha = 1.0;
activityIndicator1.hidden = NO;
[viewLoader addSubview:activityIndicator1];
[activityIndicator1 startAnimating];
}
-(void)hideLoaderView {
[UIView animateWithDuration:1
animations:^(void) {
[viewLoader setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 50)];
}];
}
then use this two methods in your API call method. Call addLoaderViewAtBottom when API call starts and call hideLoaderView after getting the responses
Happy coding...
Initialize UIActivityIndicatorView:
#interface MyBulletinVC ()
{
UIActivityIndicatorView *activityLoadMore;
}
-(void)viewDidLoad
{
activityLoadMore = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
}
Check when UITableView is being scrolled and what is the content offset
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
float bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height;
float tblBottomEdge = _tblBulletin.frame.size.height+_tblBulletin.frame.origin.y;
if (bottomEdge <= tblBottomEdge)
{
return;
}
if (bottomEdge >= scrollView.contentSize.height)
{
[self show_bottom_loader];
}
}
If applicable as per content offset then display loader in footer of table:
-(void)show_bottom_loader
{
_tblBulletin.tableFooterView = [self returnLoaderViewWhileFetchingRecords];
CGPoint newContentOffset = CGPointMake(0, [_tblBulletin contentSize].height - _tblBulletin.bounds.size.height);
[_tblBulletin setContentOffset:newContentOffset animated:YES];
[self getNewsRecords];
}
Hide footer when data is loaded:
-(void)hide_bottom_loader
{
_tblBulletin.tableFooterView = nil;
UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
v.backgroundColor = [UIColor clearColor];
[_tblBulletin setTableFooterView:v];
[activityLoadMore stopAnimating];
}
-(UIView*)returnLoaderViewWhileFetchingRecords
{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,0,_tblBulletin.frame.size.width,44)];
view.backgroundColor =[UIColor clearColor];
UILabel *lblBg =[[UILabel alloc]initWithFrame:CGRectMake(0,1,_tblBulletin.frame.size.width,42)];
lblBg.backgroundColor =[UIColor whiteColor];
[view addSubview:lblBg];
UILabel *lbl =[[UILabel alloc]initWithFrame:CGRectMake(_tblBulletin.frame.size.width/2 - 20,0,_tblBulletin.frame.size.width/2,view.frame.size.height)];
lbl.textAlignment = NSTextAlignmentLeft;
lbl.text = #"Loading...";
lbl.font = [UIFont fontWithName:#"Arial" size:14.0f];
lbl.textColor = [UIColor darkGrayColor];
lbl.backgroundColor = [UIColor clearColor];
lbl.userInteractionEnabled = NO;
[view lbl];
activityLoadMore.frame = CGRectMake(_tblBulletin.frame.size.width/2-35,22,0,0);
[activityLoadMore startAnimating];
[view addSubview:activityLoadMore];
return view;
}
-(void)getNewsRecords
{
//fetch new records and add to your array.
[self hide_bottom_loader];
//reload table.
}
Replace tblBulletin with you table name.
I want to build a custom alert by UIViewController and add its view as a subview to the current window. The view displays very well, but I can't handle any touch events.
I have tried many times to add a button to this viewcontroller and add a target. I have also tried adding a UITapGestureRecognizer and set view's userInteractionEnabled to true, but this also failed even when I cleared all subviews just left the button.
Have I missed something?
Here is the code:
CustomAlert Viewcontroller:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor clearColor];
backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
backgroundView.backgroundColor = [UIColor blackColor];
backgroundView.alpha = 0.5;
[self.view addSubview:backgroundView];
backImage = [[UIImageView alloc]initWithFrame:CGRectMake((self.view.frame.size.width - 300) / 2, (self.view.frame.size.height - 250) / 2, 300, 250)];
backImage.image = [UIImage imageNamed:#"AlertBackground"];
[self.view addSubview:backImage];
confirmButton = [[UIButton alloc]initWithFrame:CGRectMake( backImage.frame.origin.x + 100 , backImage.frame.origin.y + 250 - 40, 100, 26)];
[self.view addSubview:confirmButton];
[confirmButton addTarget:self action:#selector(confirmButtonClick:) forControlEvents:UIControlEventTouchUpInside];
confirmButton.backgroundColor = [UIColor redColor];
[confirmButton setTitle:#"click me" forState:UIControlStateNormal];
}
-(void)confirmButtonClick:(UIButton*)sender{
[self.view removeFromSuperview];
}
-(void)show{
UIWindow * window = (UIWindow*)[UIApplication sharedApplication].keyWindow;
[window addSubview:self.view];
}
Method call custom alert:
CustomAlert * alert = [[CustomAlert alloc]init];
[alert show];
Try to rewrite your -show{} method with these
UIWindow * window = (UIWindow*)[UIApplication sharedApplication].keyWindow;
[window.rootViewController.view addSubview:self.view];
UPDATE:
And if previous don't help, try to overwrite
-(void)show{
UIWindow * window = (UIWindow*)[UIApplication sharedApplication].keyWindow;
[window.rootViewController addChildViewController:self];
[window.rootViewController.view addSubview:self.view];
[self didMoveToParentViewController:window.rootViewController];
}
Those three methods establish parent-child relations.
i am trying to show UIActivityIndicator on viewDidLoad of a screen. its working in another project but not sure why it's not displayed here.
I am calling the showSplashScreen fromviewDidLoad of other screen.
+(void) showSplashScreen
{
UIView *mainScreen = [[[UIApplication sharedApplication]delegate]window];
UIView *windowBlocker = [[UIView alloc]initWithFrame:mainScreen.frame];
windowBlocker.tag = 999;
windowBlocker.backgroundColor = [UIColor clearColor];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((mainScreen.frame.size.width), (mainScreen.frame.size.height), 50, 50)];
imageView.layer.backgroundColor=[[UIColor colorWithRed:200 green:0 blue:0 alpha:0.5] CGColor];
imageView.layer.cornerRadius=10;
imageView.layer.masksToBounds = YES;
[windowBlocker addSubview:imageView];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[windowBlocker addSubview:spinner];
spinner.center = mainScreen.center;
[spinner startAnimating];
}
nothing happens. Any idea? I am trying for iPad.
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[imageView addSubview:spinner];
spinner.center = mainScreen.center;
[windowBlocker addSubview:imageView];
[self.view addSubview: mainScreen];
[spinner startAnimating];
//Yoy forget to add windowBlocker in mainview
[Self.view addSubview:windowBlocker];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = mainScreen.center;
[spinner startAnimating];
[windowBlocker addSubview:spinner];
//Try this code
looks like the issue is that you haven't added windowBlocker to the screen.
try:
[mainScreen addSubview:windowBlocker];
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self performSelector:#selector(addSplash) withObject:nil afterDelay:0.5];
}
-(void)addSplash {
[[self class] showSplashScreen];
}
+(void) showSplashScreen
{
UIView *mainScreen = [[[UIApplication sharedApplication]delegate]window];
UIView *windowBlocker = [[UIView alloc]initWithFrame:mainScreen.frame];
windowBlocker.tag = 999;
windowBlocker.backgroundColor = [UIColor redColor];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((mainScreen.frame.size.width), (mainScreen.frame.size.height), 50, 50)];
imageView.layer.backgroundColor=[[UIColor colorWithRed:200 green:0 blue:0 alpha:0.5] CGColor];
imageView.layer.cornerRadius=10;
imageView.layer.masksToBounds = YES;
[windowBlocker addSubview:imageView];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[windowBlocker addSubview:spinner];
spinner.center = mainScreen.center;
[spinner startAnimating];
[[[[UIApplication sharedApplication]delegate]window] addSubview:windowBlocker];
}
As I added some delay with 0.5 because when i called function in ViewDidLoad orViewWillAppear some reason view not initaliaze yet so i provide some delay or you can use the viewDidAppear for as an option of this situation like and only this function and remove viewWillAppear and addSplash and add only this
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[self class] showSplashScreen];
}
Change this ... it works for you
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.color=[UIColor greenColor];
spinner.center = self.view.center;
[spinner startAnimating];
[windowBlocker addSubview:spinner];
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!
when i press one button i have to display one white color uialertview with activity indicator for 5 seconds ?
i saw some codes and i select the following code ,is that enough? how can i change the color of activity indicator
myAlertView = [[UIAlertView alloc] initWithTitle:#"Loading" message:#"\n\n"
delegate:self
cancelButtonTitle:#""
otherButtonTitles:#"OK", nil];
UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
loading.frame=CGRectMake(150, 150, 16, 16);
[myAlertView addSubview:loading];
i want something like in this image with uiactivity indicator
You can create a custom alert like follow (PS: i had developed this custom alert after 3 hours of working, its compatible with iPhone4, iPhone5 and iPad ):
-(void)showAlert{
alertViewView = [[UIView alloc]initWithFrame:self.window.frame];
UIImageView *alertBackground = [[UIImageView alloc]initWithFrame:CGRectMake(-200, -200, self.window.frame.size.width*2, self.window.frame.size.height*2)];
// alertBackground.image = [UIImage imageNamed:#"alertBackGround.png"];
[alertViewView addSubview:alertBackground];
alertBackground.backgroundColor = [UIColor blackColor];
alertBackground.alpha = 0.5;
UIImageView *alertImage = [[UIImageView alloc]initWithFrame:CGRectMake(self.window.frame.size.width/2-310/2, self.window.frame.size.height/2-179/2, 310, 248)];
alertImage.image = [UIImage imageNamed:#"rommanAlertBig.png"];
[alertViewView addSubview:alertImage];[alertBackground release];[alertImage release];
UIButton *lButton = [UIButton buttonWithType:UIButtonTypeCustom];
lButton.frame = CGRectMake(self.view.frame.size.width/2-150+40-15, self.view.frame.size.height/2-179/2+118 , 120, 41);
[lButton setTitle:#"Cancel" forState:UIControlStateNormal];
[lButton addTarget:self action:#selector(removeAlert) forControlEvents:UIControlEventTouchUpInside];
[alertViewView addSubview:lButton];
UIButton *rButton = [UIButton buttonWithType:UIButtonTypeCustom];
rButton.frame = CGRectMake(self.view.frame.size.width/2-150+170-15, self.view.frame.size.height/2-179/2+118 , 120, 41);
[rButton setTitle:#"OK" forState:UIControlStateNormal];
[rButton addTarget:self action:#selector(yesAction) forControlEvents:UIControlEventTouchUpInside];
[alertViewView addSubview:rButton];
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(self.window.frame.size.width/2-310/2+30, self.window.frame.size.height/2-179/2+75, 260, 40+69)];
lbl.text = #"Description";
lbl.textColor = [UIColor whiteColor];
lbl.textAlignment =UITextAlignmentCenter;
lbl.numberOfLines = 0;
lbl.font = [UIFont systemFontOfSize:17.0];
lbl.backgroundColor = [UIColor clearColor];
[alertViewView addSubview:lbl];[lbl release];
[self.window addSubview:alertViewView];
alertViewView.alpha = 0;
[UIView animateWithDuration:0.1 animations:^{alertViewView.alpha = 1.0;}];
alertViewView.layer.transform = CATransform3DMakeScale(0.5, 0.5, 1.0);
CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:#"transform.scale"];
bounceAnimation.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.5],
[NSNumber numberWithFloat:1.1],
[NSNumber numberWithFloat:0.8],
[NSNumber numberWithFloat:1.0], nil];
bounceAnimation.duration = 0.3;
bounceAnimation.removedOnCompletion = NO;
[alertViewView.layer addAnimation:bounceAnimation forKey:#"bounce"];
alertViewView.layer.transform = CATransform3DIdentity;
}
-(void)removeAlert{
for (UIView *v in [alertViewView subviews]) {
[v removeFromSuperview];
}
[alertViewView removeFromSuperview];
[alertViewView release];
}
-(void)yesAction
{ [self removeAlert];
// Your Code here
}
Change color of activity indicator
In iOS 5.0 and up you can use setColor: on the UIActivityIndicatorView to set a custom color.
MAke a custom alertview
make a subclass
In drawrect draw white color on top of the view part
Why not use the class you took the picture from? https://github.com/m1entus/WCAlertView
For the ActivityIndicator you can just drag one out with the IB and change its color. Then do something like :
[activityindicator startanimating];
//put alert code here
// choose when you want to stop the animation:
//[activityindicator stopanimating];