i display an activityindicator like
CGRect frame = CGRectMake(0.0, 0.0, 25.0, 25.0);
loading = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[loading startAnimating];
[loading sizeToFit];
loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
self.navigationItem.titleView = loading;
in my navigationbar on the top. And i call:
[loading stopAnimating];
to stop.
This works like it should, but after hiding the activity indicator i want to display a text (self.title = #"text";) and this is not working.
What do i miss?
Thanks for your help!
Try setting the self.navigationItem.titleView to nil and then set the title.
Related
I am doing an application where i am creating a UILabels programmitically,As i will be creating some 15 labels with different frames so i using only one method and calling it by parameter passing.
when i rotate it to Landscape view the position of the labels should be changed as there will lot of space left empty at right side..so i am trying to use Autoresizing mask but its not working,so please suggest what i should do so that label frame changes and fits at right position when i turn to landscape orientation. please provide me a sample code.The present code i am using is given below.
{
[self.view addSubview:[self createLabel:CGRectMake(450,140,60,20):#"Ratings:"]];
[self.view addSubview:[self createLabel:CGRectMake(450,170,60,20):#"Reviews:"]];
[self.view addSubview:[self createLabel:CGRectMake(50,170,50,20):#"Hours:"]];
[self.view addSubview:[self createLabel:CGRectMake(50,200,50,20):#"Phone:"]];
self.view.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
[super viewDidLoad];
}
-(UILabel*)createLabel:(CGRect)frame :(NSString*)labelTitle
{
UILabel *myLabel = [[UILabel alloc] initWithFrame:frame];
[UIFont fontWithName:#"Arial" size:13];
myLabel.textAlignment = UITextAlignmentLeft;
myLabel.font = [UIFont boldSystemFontOfSize:13];
myLabel.text = labelTitle;
[myLabel autorelease];
return myLabel;
}
You should set also autoresizingMask to all subview of self.view - add, for example, next line in the -(UILabel*)createLabel:(CGRect)frame :(NSString*)labelTitle method:
myLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
or
myLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth;
I am using the following code to for Creating UILabels and calling it by paramater passing. I am using UIViewAutoSizingMask for autosize of labels when rotated in different orientation.
[self.view addSubview:[self createLabel:CGRectMake(450,240,60,20):#"Ratings:"]];
[self.view addSubview:[self createLabel:CGRectMake(450,270,60,20):#"Reviews:"]];
[self.view addSubview:[self Label:CGRectMake(505,240,60,20):aRequests.ratings]];
[self.view addSubview:[self Label:CGRectMake(510,270,60,20):aRequests.reviews]];`
self.view1.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
-(UILabel*)createLabel:(CGRect)frame :(NSString*)labelTitle
{
UILabel *myLabel = [[UILabel alloc] initWithFrame:frame];
[UIFont fontWithName:#"Arial" size:13];
myLabel.textAlignment = UITextAlignmentLeft;
myLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
myLabel.text = labelTitle;
[myLabel autorelease];
return myLabel;
}
In Portrait view it displays like this,
Ratings:3
Reviews:4
whereas, When rotated to landscape it display like this.
Ratings: 3
Reviews: 4
There is a space provided after "Ratings" Label. I have used all Autoresizing mask still its not working.
can anyone suggest anyone what is happening and what changes should be done in the above code.I tried all the autoresizeingMask everything but still i am not able to fix this.
The masks are conflicting eachother, use:
self.view1.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
and
myLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
How to add activity indicator when camera button (USE button) is pressed after making a snap.
It looks like hangs for few seconds.
Please help
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[indicator sizeToFit];
indicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
indicator.tag = 1;
[self.view addSubview:indicator];
[indicator setBackgroundColor:[UIColor clearColor]];
indicator.center = self.view.center;
indicator.hidden = FALSE;
[indicator startAnimating];
i want to add activity indicator & show at when i select didSelectRowAtIndexPath and hide at while detailView page displayed...plz help anyone.... and Give any sample Code.
-(void)showActivityViewer {
self.activityView = [[[UIView alloc] initWithFrame: CGRectMake(0, 0, self.view.window.bounds.size.width, self.view.window.bounds.size.height)] autorelease];
activityView.backgroundColor = [UIColor blackColor];
activityView.alpha = 0.5;
self.activityWheel = [[[UIActivityIndicatorView alloc] initWithFrame: CGRectMake(self.view.window.bounds.size.width / 2 - 12, self.view.window.bounds.size.height / 2 - 12, 24, 24)] autorelease];
activityWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
activityWheel.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
[activityView addSubview:activityWheel];
[self.view.window addSubview: activityView];
[[[activityView subviews] objectAtIndex:0] startAnimating];
}
-(void)removeActivityViewer {
[activityWheel removeFromSuperview];
[activityView removeFromSuperview];
self.activityWheel = nil;
self.activityView = nil;
}
MBProgressHUD does exactly that! Check out https://github.com/jdg/MBProgressHUD
I'm using activity indicator view in my app.
When I click on a button, I want the activity indicator to display in the navigation bar for 10 seconds then automatically hide.
I'm using the following code in view did load:
CGRect frame = CGRectMake(0.0, 0.0, 25.0, 25.0);
self.activity = [[UIActivityIndicatorView alloc]
initWithFrame:frame];
[self.activity sizeToFit];
self.activity.autoresizingMask =
(UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
UIBarButtonItem *loadingView = [[UIBarButtonItem alloc] initWithCustomView:self.activity];
loadingView.target = self;
self.navigationItem.rightBarButtonItem = loadingView;
And in the button action I only start the indicator:
[self.activity startanimating];
But I cannot see the indicator in navigation bar.
Please tell me if there are any problems in my code...
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
UIBarButtonItem *itemIndicator = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
[self.navigationItem setLeftBarButtonItem:itemIndicator];
[activityIndicator startAnimating];
I don't understand why you're using target (and you even do not specify an action)...anyway I just tested your code and introduced this slight adjustment. Every time I want to start the activity indicator I use this piece of code:
UIActivityIndicatorView *test = (UIActivityIndicatorView*)self.navigationItem.rightBarButtonItem.customView;
[test startAnimating];
Obviously I don't use an ivar because it's not needed. It's just a cast and from your UIViewController and you can obtain it in a very fast way.
Hope it helps.