I want my background to be an image, so in IB I set a UIImageView with the constraints to be the same size as the its UIView. However, when I select "back" on the UINavigationBar, when the NavControl pops to the previous VC, this is what's there, briefly, before it disappears:
That is, the UIImageView is so big that it is almost double the width of the UIView, so as it slides off-screen to the right, the UIImageView's image drags on before finally disappearing.
I have also tried to do this programmatically, but even if I set the UIImageView's frame to be CGRectMake(0, 0, 100, 100), it still goes off to the left side of the UIView, as if the UIView's origin weren't at the top left corner, but slightly off the screen. Is this possible? How do I make it so the image fits the screen and doesn't go off?
If it's at all relevant, the jpg I'm using is in Images.xcassets and, although I can select it in IB and it appears, the UIImageView's image is white/blank, so in my viewDidLoad method I need to specify self.imageView.image = [UIImage imageNamed:#"hockeyIce.jpg"].
go to Main.storyboard
select the view in question
click Attributes Inspector
scroll down to View, select Mode: Scale To Fill
OK, the solution was to add [self.imageView setClipsToBounds:YES] to my viewDidLoad. It turns out that this is a common problem with aspectFill.
Related
On a button click, i am opening a viewcontroller as a popup. But it should not occupy the whole screen. It should be 70% of the screen.
I tried to reduce the height of view controller with properties and CRect size. But it is not reducing the height.
how to reduce height of view controller?
its an easy fix.
add a UIView inside you ViewController and set the constraints as desired.
set the background color of the ViewController to be transparent.
click here to select the parent view in the ViewController.
then, click on the color next to background and click custom.
finally, drag the opacity all the way down to 0 as shown in the image.
I have a UIView that is a subview of another UIView. Within this UIView I have a button that I always want to be centered. The problem I am running into is that, since the subview can change sizes upon rotations, the button gets off centered. Is there a way to get auto-centering?
Try setting the button center as the uiview center like this:
[myButton.setCenter:mySubView.center];
and then set autoresizing mask:
[myButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];
Hope it helps.
Turn on auto-layout and center your button. You turn on auto-layout by selecting your view controller and on the right check auto-layout. Here is a picture:
I'm trying (everything in XCode with Interface Builder) to create a UIButton with image adding it to UIToolbar, which makes it UIBarButtonItem (when click twice it shows the UIButton properties).
I have a image#2x.png image with size 64x88 (height is 88, because in Retina it's the toolbar height). I'm not interested in non-retina screens. I added this image to UIButton setting Mode in View properties to Center (or Aspect Fit, it shouldn't really matter here; tried both, aswell).
Set its size to 32x44 (44 height in builder). Then, dragged it to UIToolbar.
Now, I want to change the width of my button to make it larger, because I want to give user some more space to tap, also, I planned the toolbar background for that. And I want the image on this button to remain the same, but centered. But, when I try to resize the UIBarButtonItem, it actually scales the image, no matter what Mode is set.
That's what happens (I'm showing an actual dragging process):
However, if I change image real size to height 44, it works well. But 44 height looks ugly in Retina devices, so, what should I do?
I've seen this happen. For the sake of argument, create two images, image.png and image#2x.png, and when setting the image of the button, select image.png in Xcode.
Alternatively, you can create a UIView-based UIBarButtonItem and have a UIImageView and a UIButton. This way, you have a more precise control over the image sizing.
the situation is as follow: the self.view contains:1, a custom bar which is actually a uiview with some buttons on it and its height is 44px
2, a uitable view y-pos starts at 44th px. the rows have 150px tall and wide button. on touching the button, a tmp uiview with similar look to the button added on the table at same position where button is. some animation block happens and uiview covers the whole table and shows some content.
so far all is fine.
now if one scrolls the table up so that bottom half is visible and the top half is invisible.
the tmp view gets added properly at the same location but while using CATransform3DMakeRotation(M_PI_2, 0.0f, 1.0f, 0.0f) the left half looks on the top of the custom bar even though the tmp view added using insertSubview belowSubview:customBar.
i tried to send the view to back but no luck.
so any idea how to resolve this issue?
that was very easy. the view which should be on the top of all even during flipping should have a large positive zposition value before applying the animation.
self.myview.layer.zPosition =200.0f;
I have a table cell with a custom backgroundView which looks great while in portrait, however when I move to landscape the backgroundView gets stretched to match the landscape width. How can I make it so the backgroundView stays the same height/aspect ratio?
This seems to do nothing:
self.backgroundView.autoresizingMask = UIViewAutoresizingNone;
Is there a solution to this? Here's some screenshots to illustrate. The first image shows portrait view properly, the second shows landscape view with the middle rows scaled when I want them to be the same size as they were in portrait, just located in the middle (much like the images above them, which are actually just UIImagViews added directly to the cell, rather than changing the backgroundView property).
Thanks!
Figured this out. All I needed to do was set the contentMode.
backgroundView.contentMode = UIViewContentModeCenter;