what I am trying to do is to have an image on which I then want to draw something by overriding the drawRect function. Essentially I am trying to create dice, where I use a background and then have the relevant dots drawn in depending on the number selected.
I created the dice dots in PaintCode paint-code and then exported that to use in Xcode (Swift).
I am creating a UIView on Storyboard that I then want to add a background image to and then draw the dots based on the number I pass it.
On it's own the drawing of the dots are working fine, but when I try and add an Image using a subview with UIImageView the image doesn't show up, the background of the UIView is white and even setting it to clearColor() doesn't work.
Any suggestions?
Related
How can I add a border to an UIImageView which is located on the LaunchScreen of an iOS App?
I already tried to do it programmatically and to add user defined runtime attributes (which is not allowed).
You cannot programmatically do this, however...
If you add an actual border to your bitmap image, the border will get "pixel-stretched" for different screen resolutions.
Another option (which would avoid that issue): You could add a UIView, set its background color to the color you want for your border, and add your UIImageView as a subview, with constraints set to 1 or 2 points to give it the desired "border width".
LaunchScreen is static so you can't add a border to an UIImageView which is located on the LaunchScreen.
An easy and possible way is you have to create an image with border you want and set it inside a normal UIImageView. Use auto layout to scale the image if needed.
I have a requirement to set a Gradient background to the launch screen with a UIImageView in the center which shows the app logo . I tried having a view controller but I realised code will never be invoked.
I need some way to get behaviour as the code below does
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "background.png")!)
I went through lot of answers about the same topic, most of the questions on gradient colour don't seem to have any additional requirements like showing another image other than the background .
I can hardcode the color in IB but i don't get the gradient.
You cannot run code or use any custom classes in the Launch Screen. Basically the launch screen can use an interface builder file and accommodate size classes / auto layout, but you cannot create a gradient in code like you have.
You'll have to supply a stretchable image, which contains enough data for it to be viable in all resolutions.
You can use 2 layers of UIImageView:
The first is large and contain the background gradient image, and a second layer of centered image (with transparent backgrount) of the logo.
I have a image and want to create a black tinted image of same as shown below:
I have a view and a image view as it's subview. The alpha of Image view is 0.5 and its tint color to Black color. Also the background color of view was set to black color. Using this the second screenshot is generated and I want a similar output to a new UIImage.
PS: I need a new image which can stored or reused independent of background views etc.
Also I have tried following so check before reporting duplicate:
How would I tint an image programatically on the iPhone?
Overlaying a UIImage with a color?
Making a UIImageView grey
iPhone: How to Dynamically Color a UIImage
I've also tried getting image from a view but that does not help as I've more components in view not shows here.
iPhone - flattening a UIImageView and subviews to image = blank image might help you with your problem. The idea is to "render in context" a UIView object with 2 subviews (the image, and the black overlay view) to get an image. If you have more subviews which you do not want in the image, simple hide them when rendering.
I currently have a main UIView that I have subclassed and set a custom background colour from a UIImage.
I also have a .png with a transparent background - lets call it myImage.png.
I want to be able to add the myImage.png to the main view so that I am able to animate the non-transparent portion of my UIImage. I assume that this could be achieved with the use of layers and image masking but I would really appreciate an example to get me started.
EDIT
To clarify, I am interested in knowing how I can use core graphics to cut out the myImage.png and reveal a tint colour. I can then animate this tint colour to give a flashing effect. I am able to animate the image without a problem, so I need a solution to the problem of 'cutting out' the image and revealing a background tint that I my animate in and out.
I am using iOS6
Thanks in advance.
You can play around with CAGradientLayer, CATransformLayer, CAReplicatorLayer.
As I understand your question you have a .png with transparent background and you want to animate the non-transparent part of this .png (myImage.png) you want to add myImage.png to your main view with an animation. Take a look of this apple documentation link of Core Animation
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/CreatingBasicAnimations/CreatingBasicAnimations.html
It will help you with what you want
So I was wondering if there's a way to make a UIView with a custom shape.
I'm trying to make a piano keyboard so when the user touches the view a delegate method responds by playing a noise. The picture is a .png with the picture of the key and a transparent background.
Thanks in advance.
You can't make a UIView in the shape of, say, a triangle, but what you can do is make the view transparent, then add your non-transparent content to it.
For example, to make a view with a background of a png (with, I assume, partially transparent areas) you could make a transparent UIView and then add an image view to it. better yet, just use a UIImageView in the place.