Watchkit: Is it possible to add an image behind a WKInterfaceLabel? - swift

I am trying to add an orange circle with a number (my number will change depending on certain circumstances) inside it in my WKInterfaceGroup like the image below.
However, it appears you can't change WKInterfaceLabel background color. The only solution I can think of is to add an image behind the label. So how can I achieve this (if it is possible)? Is there another way to make this work?

The easiest way to do this is to:
Put the Label into a Group.
Center Align and Position the layout of the Label
Set the Group to a Fixed Width and Height.
Set the Corner Radius of the Group equal to 1/2 the Width (height should be the same)
Set the Group to Background Color to the color you want.

You could add the label to a WKInterfaceGroup and set its background image property. Or, you can create pre-rendered template images and use setTintColor: to color them.

Related

Anychart DataArea Background Stroke Partly Not Visible

I want to draw a border around the data area of my chart. Therefor I use chart.dataArea().background().stroke() but the stroke is partially hidden behind the background fill color of the data area.
See this playground example:
https://playground.anychart.com/LfsMXtpR
Of course I could just make it thicker, but I want it to be the same thickness all around.
I think the stroke shouldn't be hidden by the background fill.
Thanks ahead.
The reason is that yAxis has greater zIndex then data-area. You can decrease the yAxis zIndex to solve it, check the modified sample.

Swift iOS UI Advice

I am looking for some general advice and maybe some example code of what I am trying to accomplish if anyone knows of any for an iOS swift project. I would like to either:
A) Make the background, of the blue view, gray and only show a certain percent of the blue area.
OR
B) Overlay the gray area on top of the blue view and just keep making gray area bigger.
What I am trying to do is simulate battery power and show a battery.
I've considered using a progress bar and doing option A, but the blue area is NOT a solid color. Its actually an image. I've tried using an image for the progress bar, but the image needs to keep its dimensions. (Ex: If progress shows 20% it needs to show only 20% of the image or "blue area", but if you use an image as the progress bar it just shrinks the image and still shows 100% of it instead of just the 20% I need to show).
You can easily write a custom self-drawing UIView that will behave in exactly the way you describe. In other words, you tell your UIView a percentage, and it redraws itself with the blue on the left and the gray on the right. You can even draw the darker gray stroke outline shown in your drawings. All easily accomplished in code.
I like being able to lay things out visually and take advantage of autolayout. Here's how I would do this (in a nib/storyboard):
Place a UIView on your canvas and give it the gray background. Give it whatever autolayout constraints are appropriate for you.
Place a UIView inside the one from #1 and give it the blue background. Anchor it's left, top, and bottom to the gray parent view and give it whatever width (doesn't matter).
Add an outlet to that width constraint you made in #2.
Now all you have to do is modify the "constant" property of that width constraint to give you the desired "progress". So if your gray view is 100 wide and you want to present "20%" progress, then just do "yourWidthConstraint.constant = 20".

Unity3d new UI: How to set button's interactable zone bigger than the attached image?

I need it because the image is small and it's difficult to touch it on the mobile device. So I need to have bigger area of interactable zone but the image should stay small.
I believe the most proper way to make such button is like this:
Create a new Button, remove default child Text.
Set Width and Height of Button as you need for hitzone size.
Add Vertical Layout Group component to the Button.
Set Padding of the Vertical Layout Group to desirable difference between hitzone and visuals.
Remove default Image component. Set alpha of default Image component to zero.
Put your Image as child of Button.
Fix tint: drag (or otherwise set) the child Image to Target Graphic field of Button.
You need to set it up so that the image is inside a button object. Like this:
This way you can have the Button as big as you want and the Image can be any size. If you don't need the Button background image just make the color transparent in the image componenent of the Button object.
A surprisingly better way (in terms of ease and performance) is to add a text child element, even if you already have one. Leave the text empty and resize it however you like. It doesn't add any alpha.
Unity now have Raycast Padding property on Image component, edit these padding values will allow you to have more interactable zone for your button image. Note that you use negative value to extend the click zone.
Image raycast padding

How to show two colors with percentage changes on label in iphone

I'm trying to make a functionality which will show the color of like and dislike, just like we like / dislike a video on YouTube. So, green color will represent the likes and the black color will represent the dislikes, their percentage will change on the click of two buttons, i have no idea how to do it..something like this pic but without showing the percentage
Just do the simple maths first. Calculate likes/totalHits ratio and then use a image for progressbar with center area transparent where you can fill color. Put a label behing this image and just give it green color. Then adjust the width of green colored label using this ratio we calculated. :)
Create a ImageView in xib file and set the image of progress bar with transparent center area
Create a label of same size as imageView and put it behind this imageView Created with black color
Create one more label of green color and put it in between this black label and Imageview.
Now its time to code :)
in code calculate ratio = Likes/TotalHits
Now set the frame of green label as:
CGRectMake(x,y,ratio*totalWidthOfProgressBar,height)
where x and y should be the same as of progress Bar imageView and height should also be the same, you just need to set the frame again and again while user tap on likes or dislikes button.
and to display percentage value create a label over progress bar and display value = ratio*100 in that label

How to set visible border to Gtk Image

I am having GtkImage to which i want to set visible border like a frame...
so when ever i set any image it will come with default border/frame, which will look good. :)
easiest way is to put the image into GtkFrame widget.