So I just spent like one hour Googling for some answers.
I added UIImageView with Interface Builder and I set image to some existing image.
I wanted to make the image centered, so I changed mode to centered. Worked.
Now I wanted to change the image from code. So I set image in IB to nothing and I did imageView.image = (UIImage instance)
Now the image changed, but it's not centered anymore.
Also, here's an interesting thing: I tried also not changing image in IB, I just left it set to some image and then I changed image from code. I could see both images! The one set in IB was centered (like I want it) and the new one was overlaying on the left.
Any ideas please?
Also I probably lack some basic knowledge of this View stuff, can anyone please point me at documentation where this is explained?
It sounds like you have two overlapping UIImageView subviews. One of them is referenced by imageView in your view controller and doesn't center. The other isn't referenced by your view controller but does center. The solution would be to get rid of the non-referenced image view.
I got it! Thanks James Huddleston for useful comments.
You were right. There must have been to UIImageViews.
Here's what happened. I actually used viewWithTag: to find that view (it wasn't linked directly - it was in a UITableViewCell). Well, it apparently didn't work with 0, when I changed tag to 1 - it worked.
Related
I am learning to navigate and use the features of Xcode right now and I don't understand why adding an image to a UIButton through the Attributes Inspector makes the UIButton unclickable. When adding the image, it also resizes the button on the storyboard. I can't seem to find any answers online. Could somebody explain why this behavior occurs?
Before adding the image to the UIButton:
After adding the image to the UIButton:
Edit: and preferably how to fix it :D
The unclickable scenario you described is literally impossible unless you deleted everything in the connections inspector tab. In order for the image not to resize you should use autolayout in the bottom right. Set a constraint on width and height.
I'm trying to create an image viewer that behaves exactly like the Apples Photo App. But for now I'm only interested in a single image behavior.
I've placed an UIImageView inside UIScrollView and managed to handle pretty much everything beside one thing, and that is if I zoom-in in a portion of image(for example a portrait image) and then rotate the device in landscape the portion appears to be rotated over the upper left corner instead of center.
Let me try to illustrate that. This is what I have now:
This is what I would want to happen:
Basically I believe I know how I could do it but it seems to involve a bit more coding than it probably deserves. Maybe I'm missing some simple property that I could just set to get this desired behavior.
Any hint, anyone?
self.imageView.center = self.scrollView.center;
do set [imgView setContentMode:UIViewContentModeScaleAspectFit];
I want to use a UIProgressView but I want the background to be an image to make things a bit more good looking. I'm not sure how to lay one over the other. It would be important for the background image to encompass the UIProgressView.
Any help appreciated.
You can simply create a UIImageView for your background image, then add a UIProgressView as a sub view.
You can do this in either Interface Builder or in code such as [myBackgroundImageView addSubView:myProgressView];
Obviously you will need to setup the correct frame for both to ensure they are in the correct position.
Check out addSubview: in the Apple reference.
I'm new in Iphone. I have an UITextView inside a UIImageView . Now I need to dynamically resize the UIImageView so that its textview also change its size dynamically. Moreover I can move this UIImageView with UITextView around the screen. If any one knows this using UIGuesture please help me.
Any help would be appreciated
If you are looking at resizing the UIImageView object, look at the UIPinchGestureRecognizer. It will have a property called scale that you can use to change its size.
As for the UITextView object that is the subview, you can look at autoresizingMask property inherited from UIView. Set it appropriately so that the text view scales in response to its super view.
For moving the image view, you can use the UIPanGestureRecognizer. You can get the translation using translationInView:. Use this to modify the center of the image view object. This should move the image view as you drag your finger around.
I hope you've gone through the guide. Let us know if you face problems implementing this and put some code so that we can guide you in the right direction.
I have a UIToolbar in IB with a custom UIBarButtonItem that is set to an image. The image height is larger than the UIToolbar height. The image does not load for some reason. Attached is a screenshot.
You should avoid using subviews that are larger than the parent view - even if it does work and draws the view outside of the bounds, you cannot always count on it because the clipping is skipped for performance reasons and depending on the drawing order the overlapping part of the subview might be covered later. Second problem is that only the part within the frame of the superview is able to handle the touch events.
As to why you don't see your image, it's probably a different problem, I doubt it has something to do with it going outside the frame. Post your code to get more feedback ;)