[self.navigationController.navigationBar setBounds :CGRectMake(0, 0, 320, 70)];
After increasing navigationBar's height, how can I vertically center the left- and rightBarButtonItem?
Just create a UIView and add a UILabel in it, then add that UIView as a subview to the navigationBar.(Add the UIView in the center)
Do you mean the vertical center?
You can't do this in an easy/supported way, since the extra space on top of the UINavigationBar is intended for help text and not to simply be a taller view. Consider redesigning your center view layout to deal with the fact that UINavigationBar is meant to be a fixed size.
Related
I have a UILabel centered within a UIView that expands/contracts depending on the device screen size. I've applied constraints so that the UILabel remains centered no matter the UIView size, which works fine.
Now I'm finding myself resizing the UIView manually like so (where mainView is the View Controller):
self.myView.frame = CGRectMake(0,0,self.mainView.frame.width, self.mainView.frame.height)
So this stretches the UIView to fill the whole screen/View Controller (it's also animated). I assumed the UILabel would continue to centre itself automatically, but it seems to pin itself as though it were constrained to the top of the UIView, leaving a lot of empty myView space below it.
How can I tell the UILabel to remain in the centre of the height-changing UIView that it's in?
We need to see your constraints to help, but:
You need to use centering constraints.
Set the bounds, not the frame of myView.
You might need to call setNeedsLayout on the view of the ViewController you are in
Also, set the background color of the UILabel -- it could be centered, but the text is not centered inside of it. For that, set the alignment properties.
I have an Image View that I want to center on both the 3.5 and the 4 inch screens. For some reason this is proving to be impossible. I have no idea why I'm struggling with this, it seems so basic.
Is it possible, using constraints or something, to say "center the image on both screens" because it is centered on the iPhone 5, but on the 4, it's aligned with the top, and it cuts off the bottom of the image, because the image is the size of an iPhone 5 screen.
If you want to do it without auto layout and constraints then programatically it would be something like this.
UIImage *yourImage = ....
UIImageView *imageView = [[UIImageView alloc] initWithImage:yourImage];
[self.view addSubview:imageView];
CGSize superviewSize = imageView.superview.frame.size;
imageView.center = CGPointMake((superviewSize.width / 2), (superviewSize.heigth / 2));
Go to your Storyboard file. Select your UIImageView and control-drag to it's superview. You should then be presented with a few options. Click on "Center Horizontally in Container" and then repeat for "Center Vertically in Container.
If you want to have the UIImageView cover the whole superview then click on "Leading Space to Container Margin" and repeat for "Trailing Space to Container Margin", "Top Space to Top Layout Guide" and "Bottom Space to Bottom Layout Guide" instead.
How to make tableview's scroll bar scroll in a smaller rect than table's frame?
Like this:A UITableViewController in a UINavigationController.
Tableview's frame is (0,0,320,480)(This frame said by NSLog), its scroll bar is always under 44px. So scroll bar will not displayed behind navigation bar.
How to archive this? Special thanks
You coud set scroll edge insets. For example:
UIScrollView *scrollView;
[scrollView setScrollIndicatorInsets:UIEdgeInsetsMake(44, 0, 0, 0)];
As UITableView inherits UIScrollView all this methods are available.
I have a UILabel inside a UIView and I want the label to be resized proportionally as the UIView is resize.
I was able to do so with a UIImageView but the label stays as big as I placed it in IB.
I have set the view contentMode to UIViewContentModeScaleAspectFit thinking that anything inside the UIView would be "aspect fit" but I had to set the same mode to the UIImageView (which works fine) and I can't set that mode to the UILabel.
Thanks for your help.
It appears CGAffineTransform is the answer.
myView.transform = CGAffineTransformMakeScale(0.5, 0.5);
This would resize the view and everything that is inside dividing the view width and height by 2.
set setAutoresizingMask of label
Is there a "stick-to-bottom" autoresizing mode in Cocoa-Touch? Basically, I got a UIImageView in the lower part of another UIView. When the UIView resizes, I don't want to change the UIImageView's size, but keep it in the lower part of the UIView, while only resizing the other subviews in my UIView above the UIImageView.
Is that easily feasible?
Assuming you want to have the image view resize horizontally:
imageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;