So previously in my application, I had an UIActivityIndicatorView for processes that let the User know that something is loading. I wanted to add a layer of text to inform the user such as signing up,retrieving data, etc. I created a UIView, set it's frame to be in the center of the screen, than my hope was to create the UIActivityIndicatorView in the center and the UILabel in the bottom fourth. My label appears as planned, however now my UIActivityIndicatorView does not appear anymore so I'm curious to as why. I have made sure that the UIActivityIndicatorView is white so it's visible against the black background color and checked other common pitfalls. It seems I'm not understanding something and I was curious if someone could point me in the right direction. Thanks
/*Create the UIView that will serve as the frame to our label and activity view*/
UIView *indicatorFrame=[[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-50, (self.view.frame.size.height-self.navigationController.navigationBar.frame.size.height-self.tabBarController.tabBar.frame.size.height)/2.0-50, 100, 100)];
indicatorFrame.backgroundColor=[UIColor blackColor];
indicatorFrame.layer.borderColor=[[UIColor whiteColor]CGColor];
indicatorFrame.layer.borderWidth=2.0f;
indicatorFrame.layer.cornerRadius=10.0f;
indicatorFrame.layer.masksToBounds=YES;
[self.view addSubview:indicatorFrame];
/*Create activity indicator*/
UIActivityIndicatorView *spinner=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[spinner setCenter:CGPointMake(indicatorFrame.frame.size.width/2.0,indicatorFrame.frame
.size.height/2)];
[indicatorFrame addSubview:spinner];
/*Create Text Label to be added to the indicatorFrame*/
UILabel *indicatorViewText=[[UILabel alloc]initWithFrame:CGRectMake(5,indicatorFrame.frame.size.height/2,indicatorFrame.frame.size.width-5,30)];
[indicatorViewText setCenter:CGPointMake(indicatorFrame.frame.size.width/2,(indicatorFrame.frame.size.height)*3/4)];
indicatorViewText.text=#"Logging In";
indicatorViewText.font=[UIFont fontWithName:#"Georgia" size:18];
indicatorViewText.numberOfLines=1;
indicatorViewText.textColor=[UIColor whiteColor];
indicatorViewText.textAlignment=NSTextAlignmentCenter;
indicatorViewText.adjustsFontSizeToFitWidth=YES;
[indicatorFrame addSubview:indicatorViewText];
[spinner startAnimating];
Tried your code and it works without a problem. Your problem could be somewhere else in the rest of your view controller.
Your codes' output http://i.imgur.com/6i5zxBP.png
However, the only change i did is to make the text visible by settings its background color to clear color.
My personal opinion however, is to use a library like MBProgressHUD or JGProgressHUD. They cut down your code drastically and you do not have to worry about these kind of problems.
Related
I have a UIButton backgroundImage that I use to display a weather condition image when the loading is complete. I also create a UIImageView that replaces the UIButton to animate a series of images as a progress indicator.
My question: How can fix this animated UIImageView x-axis misalignment across multiple screen sizes?
Here's what the sequence looks like on 4.7" iPhone, the red box indicates the image I'm talking about:
First, the UIImageView animating as a progress indicator (imagine it spinning, alignment is correct)
Second, the download complete, the progress indicator replaced by a UIButton with a backgroundImage:
Third, the UIImageView animating on 4" iPhone (note misalignment on x-axis):
Fourth, the download complete, UIButton replaces it, aligned correctly:
Here's how the UIImageView *progressIndicator is configured.
Note that conditionButton is the UIButton with backgroundImage of the weather condition:
self.progressIndicator = [[UIImageView alloc] initWithFrame:self.conditionButton.frame];
self.progressIndicator.contentMode = UIViewContentModeCenter;
self.progressIndicator.animationImages = #[...long series of images...];
self.progressIndicator.animationDuration = 0.5f;
[self.conditionButton setBackgroundImage:[UIImage imageNamed:#"empty.png"] forState:UIControlStateNormal];
[self.progressIndicator startAnimating];
[self.view addSubview:self.progressIndicator];
I'm pretty sure the issue is with
self.progressIndicator = [[UIImageView alloc] initWithFrame:self.conditionButton.frame];
But I'm not sure how to resolve this.
The same problem occurs when I switch to 5.5" iPhone. I have no Auto Layout warnings, and the constraints that apply to the conditionButton are:
Align Center X to superview
Width = 94
Height = 94
Bottom and Top space to nearest neighbor = default
Any help would be greatly appreciated!
I'm facing a strange request by my client.
He want's the indicator inside the UITextField to be thiner. Can i change the indicator width? is this thing even possible?
Thanks,
Yes it is possible to do width of indicator. You can do it by changing the bound text field. You can do it by drawing the rect by CGRectMake(0, 10, 0, 20)];
in given code i am showing indicator in search bar text box.
indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.frame = CGRectMake(Xaxis, searchBar.bounds.origin.y+6, 40.0, 40.0);
if(![pview.subviews containsObject:indicator])
[pview addSubview:indicator];
[pview bringSubviewToFront:indicator];
it is looking like this. this may help u to understand.
I apologize if this question is very basic. I have been googling around but can't seem to find the api/reference for a drop down alert banner/label (I do not know the proper term for this), therefore I am posting here.
This: The label/banner which has "Please enter valid email address" in it.
So here a my questions:
What is the proper term for this (alert banner? notification? label?)
I am trying accomplish similar functionality to what is shown in the image, so basically if any field is invalid, the "label/banner" expands from underneath the navigation bar with the message in it:
If this is just a UILabel, what is the simplest way of adding the expand animation?
If it is something built in, since I have seen bunch of apps do it for alerting, please let me know what its called.
Have a look here, I'm sure you will be able to find something to suite your needs.
The basic idea is that its simply a UIView that you animate down from the top of the screen (at the very basic). You can get a lot fancier by adding gradients, touch recognizers to dismiss it, etc. But pretty much to get the base line functionality you would just do something like this:
//Create a view to hold the label and add images or whatever, place it off screen at -100
UIView *alertview = [[UIView alloc] initWithFrame:CGRectMake(0, -100, CGRectGetWidth(self.view.bounds), 100)];
//Create a label to display the message and add it to the alertView
UILabel *theMessage = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(alertview.bounds), CGRectGetHeight(alertview.bounds))];
theMessage.text = #"I'm an alert";
[alertview addSubview:theMessage];
//Add the alertView to your view
[self.view addSubview:alertview];
//Create the ending frame or where you want it to end up on screen, in this case 0 y origin
CGRect newFrm = alertview.frame;
newFrm.origin.y = 0;
//Animate it in
[UIView animateWithDuration:2.0f animations:^{
alertview.frame = newFrm;
}];
Check out my project - it might be just the thing you're looking for.
https://github.com/alobi/ALAlertBanner
For easier control over animating the alert, you can embed your custom view in a UIStackView and simply show/hide it in an animation block. That way will significantly reduce the amount of code needed to animate the visibility of the alert.
Is there a way to set the color of the activity indicator (probably UIActivityIndicatorView) of a UIRefreshControl?
I was able to set the color of the 'rubber' and the indicator:
[_refreshControl setTintColor:[UIColor colorWithRed:0.0f/255.0f green:55.0f/255.0f blue:152.0f/255.0f alpha:1.0]];
But I want to have the 'rubber' blue and the activity indicator white, is this possible?
This is not officially supported, but if you want to risk future iOS changes breaking your code you can try this:
Building off ayoy's answer, I built a subclass of UIRefreshControl, which sets the color of the ActivityIndicator in beginRefresing. This should be a better place to put this, since you may call this in code instead of a user causing the animation to begin.
#implementation WhiteRefreshControl : UIRefreshControl
- (void)beginRefreshing
{
[super beginRefreshing];
NSArray *subviews = [[[self subviews] lastObject] subviews];
//Range check on subviews
if (subviews.count > 1)
{
id spinner = [subviews objectAtIndex:1];
//Class check on activity indicator
if ([spinner isKindOfClass:[UIActivityIndicatorView class]])
{
UIActivityIndicatorView *spinnerActivity = (UIActivityIndicatorView*)spinner;
spinnerActivity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
}
}
}
Well, you technically can do it, but it's not supported. You better follow Dave's suggestion, or read on if you insist.
If you investigate subviews of UIRefreshControl it turns out that it contains one subview, of class _UIRefreshControlDefaultContentView.
If you then check subviews of that content view in refreshing state, it contains the following:
UILabel
UIActivityIndicatorView
UIImageView
UIImageView
So technically in your callback to UIControlEventValueChanged event you can do something like this:
UIActivityIndicatorView *spinner = [[[[self.refreshControl subviews] lastObject] subviews] objectAtIndex:1];
spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
And that would work. It also doesn't violate App Review Guidelines as it doesn't use private API (browsing subviews of a view and playing with them using public API is legal).
But keep in mind that the internal implementation of UIRefreshControl can change anytime and your code may not work or even crash in later versions of iOS.
No, that's not possible. You'll need to file an enhancement request to ask Apple to implement this.
I'm building an application that needs an MPVolumeView to control the volume. It worked perfectly before iOS 5.1 but since the 5.1 update the thumb image is no longer vertically centered. I tried a few things like changing imagine dimensions, resizing my views (and slider) but nothing seems to work, the thumb is just not vertically centered anymore. The only way i get a centered thumb is if i use the default iOS one.
I tried adding a UISlider to another view with the exact min, max and thumb image and that one is centered fine.
Here is the code for the MPVolumeView:
MPVolumeView *volumeView;
volumeView = [[[MPVolumeView alloc] initWithFrame:volumeViewHolder.bounds] autorelease];
[volumeViewHolder addSubview:volumeView];
UIView *volumeViewSlider;
for (UIView *view in [volumeView subviews])
{
if ([[[view class] description] isEqualToString:#"MPVolumeSlider"])
{
volumeViewSlider = view;
}
}
[(UISlider *)volumeViewSlider setThumbImage:sliderHandleIcon forState:UIControlStateNormal];
[(UISlider *)volumeViewSlider setMinimumTrackImage:leftTrackImage forState:UIControlStateNormal];
[(UISlider *)volumeViewSlider setMaximumTrackImage:rightTrackImage forState:UIControlStateNormal];
volumeViewHolder is just a UIView thats 153x33. I put the thumb in green in the screenshot.
Maybe a better solution:
User a bigger image with a transparent border on the bottom. Should be around 10px for Retina Displays.
the same problem i resolved in one project. Must be set color of left part and right part with alpha = 0 -it means transparent all slider without thumb (without moovable part of it). After we must create custom view for line of slider, without thumb. In this view any colored part may be shifted as you want, upper or below, left or right. It obtained using the defined y for your ocassion:
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(x,y,width, height)];
And add the slider to this line as subview. Resulted view will be slider. For example:
UISlider *ourSlider = ...;
//initialise UISlider
ourSlider.minimumTrackTintColor = [UIColor colorWithRed:0 green:122.0f/255.0f blue:1 alpha:0];
ourSlider.minimumTrackTintColor = [UIColor colorWithRed:0 green:122.0f/255.0f blue:1 alpha:0];
UIView *lineOfSliderWithoutThumb = ... ;
// creation it
[lineOfSliderWithoutThumb addSubview:ourSlider];
//after this lineOfSliderWithoutThumb is the our custom uislider.
Note: colors there are used as default slider colors of left and right sides of UISlider.