I'm subclassing UIImageView to create sprites, which move around the screen in an app I'm working on. I have a new requirement to add another image to the view, underneath the original view. If I were building this from scratch, I'd composite them as subviews of a common view and use the sendSubviewToBack method for the subview containing the image that needs to go to the back. I'll re-engineer things this way if I have to, but if there's a way to do this in the existing UIImageView, I'd rather do that.
Think of the new image as a shadow or light beam from the original image. They move together, but the original image needs to be on top.
The view will always contain the original image, but it may or may not contain the new image.
Related
I hope this question makes sense.
I have 2 images in my viewcontroller. One is for a background and the second I need to move around on top of that image freely. I am using autolayout for the background image, but when I test on different devices the second image is not in the proper place because I am not using the autolayout on it and therefore it does not move correctly.
How can I move the image to be in the proper place. Is there some way to set it properly in code. I guess I mean how could I set the autolayout in code since this image will have many positions it needs to move to.
I am trying to add an UIImage to my ViewController in the Interface Builder without overlapping all my content. Is there a way to do so? Whenever I place it you can kind of see through it, but I just wanted to hide it if possible (without deleting it) because it becomes bothersome to rearrange the position of the other elements (labels, buttons, views, etc). I know I can do it programmatically (which I've done so) but I just wanted to know if there was an IB alternative.
As an aside question I would like to know how does iOS handles the size of the images (resolution), because the image I am assigning as my VC background (programmatically) it's high resolution, and UIImage does not have a property .contentMode, therefore I cannot assign it as aspect fit.
Thank you for your help in advance!
Cheers!
Drag the image view behind other views in the left panel for the view controller in IB.
I'm trying to do a rounded images to be shown in my WatchKit application but I don't find any method to do it programatically.
What I have done to perform that, it is use my original image as a group background and put inside a mask image with rounded shape but I think this is not so clean.
Another different solution that I have thought is to create in my backend a new thumbnail or similar with the shape I want to show, but this require more time to be programed.
I could use also radius parameter from WKInterfaceGroup but, in my case (see the image below), I will lose my notification bubble that I have in a corner.
My app interface:
Uber application example:
Put your WKInterfaceImage inside a WKInterfaceGroup and round the corners of the group in Interface Builder.
What you are trying to create is not possible at the moment (we'll see if Apple will add new features to WatchKit this Summer). You'll need to mask your icons on your device and cache on your Watch.
As 'bgilham' said you could put the WKInterfaceImage inside WKInterfaceGroup, but you don't have to. You can just set the background image of WKInterfaceGroup. This time you can create some shiny fake subviews. WKInterfaceGroup inside WKInterfaceGroup with different background images on them.
For example. Lets say you have three ui (WKInterface) elements 'iconGroup', 'badgeGroup', 'badgeLabel'.
Center badgeLabel inside badgeGroup. Set badgeGroups radius to half of its height. If badgeGroups width is equal to its height you'll get a nice circle. Place your badgeGroup inside iconGroup at the top right corner. You can now set the radius of iconGroup equal to the radius of badgeGroup. Set the background image and you'll get a nice rounded rectangle with an dynamic badge.
You also can hide some items (groups) and fake some dynamic changes inside your watch app. There is tons you can create with such fakes. If you will add some animations (for example .png files) you can create fake views with transparent overlays and so on.
UPDATE:
I checked the uber screenshots of uber app, because I was wondering how they created that overlay over the map. My only clue is that they creating a lot of images on their iPhone and sending them to the apple watch to animate the background image of the WKInterfaceGroup. If the images are cached they will play 30fps on the watch otherwise its going to be 10fps or so.
My statement:
So rethink your design, its not always good to make a design like everyone else do. Create something shiny and new so people will memorize your work. :)
Hope this will help you guys out there to rethink your work and create some cool watch apps. Day one apps aren't that great at all, only a few of them are.
You can actually achieve this by using three groups:
The 1st WKInterfaceGroup has your original non-cropped image as its background.
The 2nd WKInterfaceGroup, which is inside the 1st one but has the same size, has the circle image mask as its background.
The 3rd WKInterfaceGroup, which is inside the 2nd one, contains your badge. You can put the text label in it.
Although this requires a pure simple background so the mask image can simply just overlay above the background image, this one doesn't require any image data transferring between the phone and the watch.
The only way to do this right now is just as you said. To mask the profile image into a circle, add it to a group, then add the notification bubble group as a sub-group of the main one (with a circular radius and the label inside.)
Right now there is no way to have a sub-group ignore its parent's clipping radius.
i have used UIImage category from http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/.
this has a Category for Rounded corner images, worked for me in watchkit app.
I have an image on my view, which I add programmatically & and not through storyboards. The image gets animated to move up the screen. At one point it crosses paths with several buttons and labels, which contain important text that gets blocked by the image passing over them. I want the image to move under the labels and buttons so that the text remains visible. Based on this answer IPhone Interface Builder: Z-Index, Z-order of a button, image, ui element, etc?, I tried to use editor => arrange => sendToBack/sendToFront, however, I don't think this is having any effect because the image doesn't appear in the tree of elements in the storyboard. As noted, it gets added programmatically at a certain time. Is there a way to do this?
I believe you can use [view insertSubview:imageView atIndex:0] which will place it behind all other subviews. Depending on what other subviews you have, you may need to increase the index as it controls what is placed over what in the view (lower index will go behind higher index)
As in answer to this question: Difference between addSubview and insertSubview in UIView class
If you're using addSubview:, your view will be placed on top. To control it's depth use either insertSubview:atIndex: (at exact place from bottom) or insertSubview:aboveSubview: or insertSubview:belowSubview: (which places new view above/below another known object in view hierarchy).
I have a UITableView with several sections. In each section are rows with various items. I have a custom UITableViewHeaderFooterView for each section and I would like to set the background image for each one to illustrate a particular percentage associated with each section.
I was thinking I could have a simple image with a line and two colors on either side and somehow scale/translate this image so that the line and bar color would fill up the table header from left to right in accord with the percentage value for that section. This changes so I would need to be able to re-draw it whenever the values change.
I figured that if the image did not scale to fit, but rather the left and right edges were set to bleed instead of tile, then I could just reposition the image in the view. But I'm not quite sure how to go about that, or even if that's a reasonable thing to do. Just looking for advice on a good approach for this sort of effect.
You can add image to the image view and can show the percentage of the image to the image view as per the percentage you get in that particular sections.Fill your image view with full image and display the percentage accordingly.
Instead of using an image, create a custom UIView subclass. Give it a property or two to represent the data. Then implement the drawRect: method to draw the graph.
Use this custom view in the table header/footer view instead of an image.
This has the advantage of being more flexible. If you want the graph to be fancier or different, just update the drawRect: method as needed.