Progress bar with image - ios

I am trying to make a progress bar with 2 images. One of them is grey and the other picture is green. When I click the button, I want to progress it, but it is not working.
Here is the my code (progressGreen and progressGrey are UIImageViews):
- (IBAction)nextButton:(id)sender {
self.progressGreen.tag = rowNumber; // I am giving a number
[self progess];
}
-(void) progess {
CGRect rect = self.progressGrey.frame;
rect.size.width = (rect.size.width * (self.progressGreen.tag)) / questions.count;
self.progressGreen.frame = rect;
}
What is my mistake?

Use the progressImage and trackImage properties on UIProgressView. This will be much easier than doing it manually.

Related

UIWebView black color at bottom increases with Animation?

There are some posts, where UIWebView bottom is black and can be resolved by two simple ways.
1. Clear Background of UIWebView
2. Set Opaque to NO.
However, this only solves problem for static UIWebView which is not changing its Frame or Constraints.
In my case, I have a UIWebView, It is very simple Drag and Drop on Storyboard's ViewController's View. No Inheritance. I set Background clear and set opaque to NO.
It looks fine up to now. But when I apply animation, using Facebook POP library
1. SetOpaque = YES, With Animation is clips the UIWebView's content showing black color.
2. SetOpaque = NO, With Animation is clips the UIWebView's content showing nothing (a View or something comes in front)
-(void) setConstraint {
_topConstraintValue = self.topConstraint.constant - 200;
NSLog(#"Value is UP %f " ,_topConstraintValue);
}
- (IBAction)animateUp:(UIButton *)sender {
[self setConstraint];
[VSAnimation popChangeConstraintForBasicAnimation:self.topConstraint begin:0.5 newConstant:_topConstraintValue withDuartion:0.5 isEaseInAnimation:NO withCompletionBlock:nil];
}
-(void) setConstraintDown {
_topConstraintValue = 0;
_topConstraintValue = self.topConstraint.constant;
NSLog(#"Value is Down %f " ,_topConstraintValue);
}
- (IBAction)animateDown:(UIButton *)sender {
[self setConstraintDown];
[VSAnimation popChangeConstraintForBasicAnimation:self.topConstraint begin:0.5 newConstant:[self getAnimatableConstraint:_topConstraintValue] withDuartion:0.5 isEaseInAnimation:NO withCompletionBlock:nil];
}
-(float)getAnimatableConstraint:(float)constant{
return constant+200.0;
}
-(float)getReverseAnimatableConstraint:(float)constant{
return constant-200.0;
}
Where, method inside VS is as below
//VSAnimation.m
+(void)popChangeConstraintForBasicAnimation:(NSLayoutConstraint *) layoutConstraintToPopChange begin:(float) beginTime newConstant:(CGFloat) newConstant withDuartion:(float)duration isEaseInAnimation:(BOOL)isEaseIn withCompletionBlock:(void (^)(POPAnimation *anim, BOOL finished)) completitionBlock{
NSString *key = [NSString stringWithFormat:#"constraints_changed_%#", layoutConstraintToPopChange];
POPBasicAnimation *basicAnim = [layoutConstraintToPopChange pop_animationForKey:key];
if(basicAnim){
basicAnim.toValue = #(newConstant);
basicAnim.completionBlock = completitionBlock;
}else{
basicAnim = [POPBasicAnimation animationWithPropertyNamed:kPOPLayoutConstraintConstant];
if(isEaseIn)
basicAnim.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
else
basicAnim.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
basicAnim.toValue = #(newConstant);
basicAnim.completionBlock = completitionBlock;
basicAnim.beginTime = [self timeWithDelay:beginTime];
basicAnim.delegate = self;
basicAnim.duration = duration;
[layoutConstraintToPopChange pop_addAnimation:basicAnim forKey:key];
}
}
What is this black line/transparent line at bottom.
How to stop this from increasing when one animates UIWebView.
IMAGES:
SHOWING ANIMATION UP & ANIMATION DOWN.
#VS, After reading you source code, I saw the constraint of the 2nd webview seems to be set wrongly. After I removed the height constraint WV2.height = 0.095 * height, the problem disappeared. You have to set the WV2's height constraint properly.

UIButton Label Showing 0 Width

I've got a Custom Button class that I'm setting up the text for in my storyboard file. The text is a simple "Update Email Address" and does not change throughout the life of the app.
However, I have an image I want to add to the button, and when I do that, I set the image in the following way, in a method inside the common button class:
[self setTintColor:[UIColor whiteColor]];
UIImage *icon = [UIImage imageNamed:iconName];
CGFloat iconWidth = icon.size.width;
[self setImage:icon forState:UIControlStateNormal];
[self setWidth:self.width+iconWidth*2];
[self setOriginX:self.x-iconWidth];
[self setTitleEdgeInsets:UIEdgeInsetsMake(0, -iconWidth*2, 0, 0)];
CGFloat leftMargin = 10;
CGFloat moveLeft = self.titleLabel.frame.size.width + self.titleLabel.x + leftMargin;
[self setImageEdgeInsets:UIEdgeInsetsMake(0, moveLeft , 0, 0)];
However, by setting it this way, it appears the titleLabel's width is 0 so the image isn't being set in the correct location on the button.
My thoughts on why this are happening are potentially because I never set the text programmatically, only in the storyboard, although that really doesn't make sense, it's all I got.
Does anyone see anything wrong here? If you need any other code let me know and I can post up the relevant info.
When do you do this? Maybe you are trying to do this after the resource was loaded but before the frames of all the elements are set.

How To Use CCSlider in Cocos2d v3.2.1?

I am new in cocos2d iPhone development.My question is how to use CCSlider in Cocos2d v3.2.
CCSlider has only two parameter (background spriteFrame and HandleImage).How we can change the colour/Image of slider when we change the Thumb position.How we can differentiate between empty and full bars, how to make progress of filling?
Suppose I want to use to colour like red(Empty) and green(Fill)/two different images for slider.By default the slider colour is red means the slider value is 0.0f(Empty).if I increase the value of slider then the slider colour will change to green(Fill) from position 0.0 to current thumb position.Please help me.sorry for my question i am very week in english
Thank You.
Here is how i use CCSlider for volume control. This code is in the init method of a GameOptions menu class:
CCSpriteFrame *frRuler = [CCSpriteFrame frameWithImageNamed:#"slider_track.png"];
CCSpriteFrame *frKnob = [CCSpriteFrame frameWithImageNamed:#"slider_knob.png"];
_mainGain = [[CCSlider alloc] initWithBackground:frRuler andHandleImage:frKnob];
[self addChild:_mainGain];
[_mainGain setTarget:self selector:#selector(onMainGainChange:)];
_mainGain.anchorPoint = ccp(.5, .5);
_mainGain.visible = YES;
_mainGain.positionType = CCPositionTypePoints;
_mainGain.position = ccp(kScreenWidth / 2, kScreenHeight / 2 - 55);
_mainGain.continuous = YES;
_mainGain.sliderValue = _battlesSettings.audio.masterVolumeGain; // initial
with the following method to receive the slider control 'slide' events :
- (void)onMainGainChange:(id)sender {
CCSlider *sl = (CCSlider *) sender;
_battlesSettings.audio.masterVolumeGain = sl.sliderValue;
_isSettingsDirty = YES;
}

Custom UIProgressView with image

I’m trying to make a custom UIProgressView where the image that gets filled up is the Nike Swoosh. I’ve tried to follow some tutorials but am getting nowhere.
My current approach:
Make the inside of swoosh transparent and surroundings black.
Then put a big UIProgressView behind that.
Since the middle of the swoosh is transparent, it looks like the swoosh is filling up.
But, modifying the height of the progress bar has proven to be a pain since it messes with the width in a weird way…and it’s hard to align the swoosh with the progress bar for responsiveness.
Are there any other ideas or libraries out there?
Thanks
My suggestion:
draw a second image programatically to apply as a mask against your 'swoosh' image, and then repeat this cyclically.
example, fill image from left (mask it from right)
{
//existing variables
IBOutlet UIImageView *swooshView;
}
-(UIImage *)maskImageOfSize:(CGSize )size filledTo:(CGFloat )percentage{
UIGraphicsBeginImageContextWithOptions ( size, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColourWithColour (context, [UIColor blackColor].CGColor);
CGRect fillRect = CGRectZero;
fillRect.size.height = size.height;
fillRect.size.width = size.width * percentage / 100.0;
fillRect.origin.x = (size.width - fillRect.size.width);
CGContextFillRect(context, fillRect);
UIImage *result = UIGraphicsGetImageFromImageContext();
UIGraphicsEndImageContext();
return result;
}
-(void)fillSwooshToPercentage:(CGFloat )percentage{
percentage = ((CGFloat ) fmaxf ( 0.0 , (fminf (100.0, (float) percentage ) ) );
// just policing a 'floor' and 'ceiling'...
swooshView.layer.mask = [self maskImageOfSize:self.swoosh.bounds.size filledTo:percentage];
}

image has too big height to display

Please, help me study objective-c!
My program takes a screenshot of whole UIWebView content, saves it, and supposed to display it.
It works fine, until it meets a very long page. Seems like the height of a page is an issue, since it displays 5 Mb screenshots just fine, as long as they are not too long (don't have to much height), however 1Mb but extremely long screenshots do not display in the UIImageView at all. It displays the UIImageView's background and that's it.
My code, attempts to resize the page to be maximum 2000 in height, and minimum 75% of the whole screen size. Aspect ratio is secondary. However, the image is still missing:
- (void)viewDidLoad
{
[super viewDidLoad];
CGFloat divider = 2;
CGFloat imageDisplayLimit = 2000;
CGFloat width = _image.size.width;
CGFloat height = _image.size.height;
//determine the leading parameter (just in case of a fat-S image)
if (width > imageDisplayLimit || height > imageDisplayLimit) {
if (width > height) {
divider = width / imageDisplayLimit;
} else {
divider = height / imageDisplayLimit;
}
}
//don't let it get too fat
CGFloat minimumWidth = self.view.frame.size.width / 1.5;
if (width / divider < minimumWidth) {
width = minimumWidth;
} else {
width /= divider;
}
//don't let it get too long
CGFloat minimumHeight = self.view.frame.size.height / 1.5;
if (height / divider < minimumHeight) {
height = minimumHeight;
} else {
height /= divider;
}
_imageView = [[UIImageView alloc] initWithImage:_image];
_imageView.frame = CGRectMake(0, 0, width, height);
//now just to make it obvious - red background
_imageView.backgroundColor = [UIColor redColor];
_imageView.frame = CGRectMake(0, 0, _image.size.width / divider, _image.size.height / divider);
_imageView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin);
_imageView.contentMode = UIViewContentModeScaleAspectFill;
[_scrollView addSubview:_imageView];
_scrollView.contentSize = _imageView.bounds.size;
_scrollView.delegate = self;
//just to make scroll visible during debug
_scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
...
At this point nothing shows, but the red background on a scrollable view.
I'm studying objective-c and don't know A LOT, but I was trying to find a solution for 2 days now. Please, save me!
My guess is aspect fill or fit doesn't do anything just because they don't actually change the image - just a display. What I really should be using (IMHO) is the UIGraphicsBeginImageContext. But I simply don't know how to make it shrink to max 2000 px. I am able to cut it by using
UIGraphicsBeginImageContext(someSizeWith2000Height)
[originalImage drawInRect:CGRectMake(resized_x, resized_y, resized_width, resized_height)];
UIImage* resized_image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
or something like that, but I don't wanna cut it - just shrink (or stretch if too short).
Any ideas? I've run out of those.
Well, since stackoverflow's system is so great, it drops questions between the desks and none can find them, I had to give up on this problem, and the only solution I could come up with is replace UIImageView with UIWebView as an image-displaying view. It makes the image displayed with TERRIBLE quality, but at least it is displayed.
Please, if anyone finds this question by chance and can help.... help! :)

Resources