ProgressHUD width size not changing UI - ios

As I continue working on my fitness app to add features, I stumble occasionally. I am having difficulty getting the ProgressHUD to update the view size. I know that a value is sent to the properties of the view but the width does not change in the UI. Here is the code I'm using for updating.
// linked to view that needs to change size when progressHUD is updated
#IBOutlet weak var progressHUD: UIView!
// this is set inside a timer that fires every 20 seconds and should update progressHUD
progressHUD.frame.size.width = (view.frame.size.width/10) * CGFloat((userHeartRate/Double(maxHeartRate)))
Here is the GUI:
The app gets the users current heart rate, compares it to the maximum heart rate to get a percentage of the maximum heart rate. This percentage is represented by the progressHUD (gray bar beneath Warm Up) and should move to the right based on the percentage of the maximum heart rate.
I know that the values are calculating correctly and assigning the value to progressHUD.frame.size.width but the gray bar does not reflect the value assigned to it.
I have installed the cocoapod for ProgressHUD and I believe everything to be working correctly. (There were no errors on the install)
There must be something simple that I am overlooking!
Any help provided is greatly appreciated.

You seem to have an unnecessary divide by 10 in your formula.
If you want progressHUD to vary from 0% to 100% of the width of the view's frame. then you should do:
progressHUD.frame.size.width = view.frame.size.width * CGFloat(userHeartRate)/CGFloat(maxHeartRate)
Assuming userHeartRate doesn't exceed maxHeartRate, then CGFloat(userHeartRate)/CGFloat(maxHeartRate) is a value between 0.0 and 1.0. Multiplying that the the view's width gives a value 0% to 100% of the view's width.
You might want to throw in a max() function if userHeartRate can exceed maxHeartRate:
progressHUD.frame.size.width = view.frame.size.width * max(1.0, CGFloat(userHeartRate)/CGFloat(maxHeartRate))
Since your progressHUD view is laid out in the Storyboard, you might want to use Auto Layout to size it. Get an outlet to the constraint for the view's width:
#IBOutlet weak var progressHUDwidth: NSLayoutContraint!
Then update it by setting its constant property:
progressHUDwidth.constant = view.frame.size.width * ...

Related

UIProgressView not reflecting first 0.05 of progress

It seems to me that when setting a UIProgressViews progress to a value between >0.0 and 0.05 always shows a progress of 0.05 (no matter the value).
I understand that this makes sense from a UX perspective, but does UIProgressView have a property to turn it off?
Judging from the PlayGround below and from #Rohan Bhale's comment, UIProgressView scales it's progress layer according to the view's frame size. The smaller the width, the less difference you will see at small .progress ranges.
At 200 points width (as depicted below), there are in fact noticeable differences in your 0 .. 0.05 range.

UIDatePicker getting cut

I added UIDatePicker to the UI and gave proper leading and trailing margins. Somehow, a part of W in Wednesday and part of M in Monday are getting cut.
Attached images. I tried increasing and decreasing leading distance from superview but no luck. Can anyone please point me in the right direction?
If we talk about Date Picker, whenever the date with Mon/Wed is selected it is does not get proper space to show the complete info of that particular date. I just try the something with DatePicker.
If datePicker have complete width, then it does not cut 'M' or 'W'.
If i diminished the width after certain level it starts cutting little portion of 'M' or 'W' and inter space between components is manageable automatically by x-code, Now I rotate the simulator, datePicker is working properly because my constraints is according to width of the simulator as it rotated in landscape datepicker get wider.
Suggestion for your problem : Give DatePicker appropriate width otherwise it behaves like this always.
Unfortunately UIDatePicker does not handle change of the width properly and it always cut Wed and Mon words if the width is less than 320. If you really need to make the width lower than 320 you can solve this with CGAffineTransform. You need to keep the width set to 320 and use transform property to change the scale of the view:
self.transform = CGAffineTransformMakeScale(280.0 / 320.0, 280.0 / 320.0);
This will make the UIDatePicker smaller and it won't cut anything.

Swift / how to change autocontraint value depending on screen size

I am using an extension to identify the device. I have a UIImage that appears too large on an iPhone 5S. I want to scale the constraint depending on the device. I want it to be like that:
if modelName == "Simulator" {
cell.eventsImageViewWidthContraint = Original * 0.8
}
What is the right code to change the constraint size (at the moment 360), to about 0.8 this size.
It looks like you're constraining the width of the ImageView to be a constant at the moment. There are 2 options I'd suggest as an alternative to using a constant. I'll assume you're using Interface Builder.
Constrain the left and right edges to a certain distance from the containing view.
Constrain the width to be a ratio of the width of the containing view. This can be accomplished by ctrl+dragging from the image view to its containing view and choosing "Aspect Ratio." You can fine tune what dimensions you're enforcing a ratio on by clicking the constraint in Interface Builder and adjusting values in the Size Inspector.
You can also try Size Classes to change the dimensions of views based on the general size of the screen.
If you are using code follow the advice above. If you are looking for an easy solution in code get the frame of the size view and calculate using those numbers. For example:
yourView.bounds.width = 0.5 * yourRootView.bounds.width
This code sets the width of a view to half the width of its root view

What is the "Adjustment" preference in WatchKit-Storyboard for?

I couldn't really find anything on the web yet, what the Adjustment preference on WatchKit's UI elements does.
Does somebody know?
The adjustment will add or subtract that many points from the size of the element. Say you have an element who's height is set relative to the container at 50% and then you add an adjustment of 10. If the containers height is 100 then that element's height will be 60 since it will be 50% of 100 plus 10. I am using it in my app to get the exact height that I want relative to the height of the watch.

ios UIImage reveal over another UIImage animation

i have two images of exact size . Imagine two images of a room, one with sunlight and another with artificial light.I have to place them one over other and add a slider,so that when slider is moved the below image will show according to slider value. Ex - If slider is on half position then user will be able to show half of image with sunlight and half with artificial light giving it a curtain effect.
i have searched a lot and failed to find any clue as how to do this. Please suggest any tutorial to do this kind of animation.
Thanks
Set the sliders minimum value to 0 and it's maximum value to 1
[mySlider setMinimumValue:0.0f];
[mySlider setMaximumValue:1.0f];
When the slider is changed by the user get the current value
float sliderProgress = mySlider.value;
adjust the alpha values of both images dependant upon the value.
[imageSunlight setAlpha:sliderProgress];
and the other image's alpha would be
[imageArtificialLight setAlpha:(1.0f - sliderProgress)];

Resources