I want to create a navigationbar like the one on the image
I know hot to make the 4 borders rounded but I need only the top borders to be rounded....
You could use an image with rounded corners at the top and square corners at the bottom.
Alternatively, check out this SO question.
Related
I'm trying to make an NSTextField with only two rounded corners on the top-left and bottom-left. I tried to do the following, but in this case I get all corners rounded:
[self.myTextField:YES];
self.myTextField.layer.cornerRadius = 5;
What should I do to have only two (or for example one) rounded corners?
I'm a little out of my lane in OS X, but what you want to do is embed whatever corner art you like into an image and present those on an image view behind the NSTextField.
Resize the image view exactly as you do the text field, but first set the image's capInsets property. Size the insets to exclude the corners from scaling as the extent of the image changes. (Make sure your corner art is placed at the extreme edges of the image).
I don't want to do this programatically. Please show me the storyboard way to achieve this.
I want orang view to of half size of the space between nav-bar & tabbar. Refere dashed rect, I want half of that rect.
There are a couple of ways to approach this that I can think of.
Use a container view
The first is to add a UIView to the superView to act as a container. You can "pin" this container view to the bottom of the navigation bar and the top of the tab bar.
Now add your orange view to this container. With constraints pinning it to the top, left and right. You can then give it equal height with the container and a 0.5 multiplier and it will have half the height between the nav bar and tab bar.
Use a "spacer" view
The other method is to use a spacer view. Add your orange view and then add another view beneath it. Pin them to the nav bar and tab bar respectively and give them a vertical spacing of 0 between them.
Now give them equal heights.
This will make them both take up half the space between the nav bar and the tab bar.
Now make the "spacer view" hidden. It will hide but the constraints will still work.
Both of these will work for any device size and any orientation. Also, for edge cases like if satnav guidance or an incoming call changes the height of the nav bar etc...
As #Fogmeister mentioned You can use spacer view
Pin both of them and make their heights Equal Height.
And set blue view Hidden.
Very easy, add the following constraints.
Left and right constraints pinning the view to the superview.
Top constraint pinning view to superview with a constant of 64 to offset the nav bar.
Equal heights constraint with the superview. Change the multiplier of this constraint to 0.5 and the constant to -54 (half of the 64pt nav bar + status bar and half of the 44pt tab bar) and update frames.
Job done. :)
Here is my problem.
I have a square image which does not fit on an iPad or iPhone app, as the screens are not square, so i decided to add a UIImageView which:
When the Phone is on Portrait position i add a constraint to the top (-20) and bottom (0) to fill the whole screen aligning X in the center and keeping the aspect ratio to keep the image square even if the screen is bigger or smaller, this means that in both sides i will "loose" part of my image, but that is fine.
When I rotate my phone to landscape position, the screen is widder,so i see a square image in the middle of the screen but a white rectangle in both sides.
I think the sollution to this is when it is on landscape position i need to remove the top and bottom constraints and add one to lead (-20) and one to trail (-20), center the image on Y axis and keep the 1:1 ratio...
But my question is: how to add a constraint to valid for one orientarion and change it to the other?
What is the best approach?
thanks
FP
You don't need to do it programmatically. I recommend you make the view fill the superview -- have one constraint each to top, bottom, left, and right. Then for the UIImageView attributes inspector in Interface Builder, set "View Mode" to Aspect Fill.
I think you have it the wrong way around.
While on portrait you should set trail and lead constraints as your height is bigger than the width, so if you set (0) for trail and lead and 1:1 ratio you are safe that it will fit beautifully. Also center it vertically in container.
On landscape, as the width is bigger than the height, you should set top and bottom (0) and ratio 1:1 and center it horizontally in container.
I want to have a larger frame than an image so i do something like this:
And of course i have UIScrollViewDelegate and i handle the zooming. But there is one problem. When i zoom picture i can scroll to this "blue" empty space in a zoom mode.
After zoom when my zoom picture width is greater than scrollView width i wish that user cannot scroll to this empty space. How can i achieve that?
(1) zoomScale 1.0:
(2) after zoom and move to edge:
(3) what i want it to be:
EDIT:
After setting contentInset:
[self.scView setContentInset:UIEdgeInsetsMake(0, -30, 0, -(self.frame.size.width-csc.width/2))];
Why it is moving to left?
There might be a simpler approach, but one way that works is to use a negative contentInset (UIEdgeInsets) to the scrollView.
I wanna draw a UIButton filled with a red tint color or some color else presented by rgb and only the upper edges are rounded.
some people answer me to get an image to do that but every time i want to change it i have to bring new image and replace it, I wanna ask can i do it from code without get an image.
There is no direct way. Only way to achieve this to create a segment control and keep only a single segment in that.
See this post for detailed implementation,
Update:
If you want to round only two corners check Round two corners in UIView or Just two rounded corners? as mentioned in rdurand's comment. Since segment control is a subview of UIView, this should work.
You can draw the rounded corners using NSBezierPath s bezierPathWithRoundedRect:xRadius:yRadius: method. And then draw over it with another bezier path. Or you could just define a custom bezier path using moveToPoint: lineToPoint: and curveToPoint:controlPoint1:controlPoint2:
Take a look at this:
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSBezierPath_Class/Reference/Reference.html