Rectangular UIButton - ios

I've read that you can make a UIButton rectangular by setting the cornerRadius, but is this only applicable to custom UIButtons? Is there a way to set the cornerRadius to zero on a default UIButton?

RoundedRectangle Button type means that it would be rounded corners, I don't think it is possible to to set radius to 0 for this button according to my experience, however you could set the background image to it or use custom button type it is quite simple as you have mentioned in your question yourself.

To make a UIButtonTypeRoundedRect type of UIButton rectangular, give the button a rectangular background image (e.g. with setBackgroundImage:forState:).

Related

How to add a border to an UIImageView located on the LaunchScreen?

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.

How to scale image UIButton to the insets?

I have this UIButton but the insets are not on the image so the button can be activated if the user taps outside the bounds of the image but inside the insets.
How do I fit the image correctly using Interface Builder?
Thank you
note: with rectangular buttons works great but not rounded squared for some reason...
you should add the picture name in the arrow location:
Duh! I had a subtle "drop shadow" on my button style so I deactivated and now it scales good :)

Hiding and showing UILabel with rounded corner and shadow in Swift 2

I am using this method Swift - Problems with corner radius and drop shadow to add rounded corners and shadow to a UILabel.
However, I need to hide and unhide the label depending on content. I am setting hidden true/false in my ViewController class. But the shadow layer still shows.
See example images below.
What is the best way to hide/unhide this shadow layer as well?
Set the alpha to 0:
myLabel.alpha = 0

No Round Rect Button in Xcode 5?

Is drag and drop of round rect button no longer available in Xcode 5? I can't seem to find it in the Interface Builder. I was guessing that this is one of the changes in iOS 7, but I just wanted to make sure.
Can also make the rounded rect within the storyboard.
The Round Rect button from Xcode 4 and previous versions appears to have been replaced with the System Default button, which also happens to be clear. I.e. by default there is no white background with rounded corners, only the text is visible.
To make the button white (or any other colour), select the attributes inspector and scroll down to the View section:
Select Background and change it to White:
If you want rounded corners you can do so with a little bit of code.
Just ctrl-drag from the button to your .h file, call it something like roundedButton and add this in your viewDidLoad:
CALayer *btnLayer = [roundedButton layer];
[btnLayer setMasksToBounds:YES];
[btnLayer setCornerRadius:5.0f];
This was too long for a comment in #Robert's answer, but I just wanted to add regarding the statement: "The Round Rect button from Xcode 4...appears to have been replaced...".
Confirming that it definitely has been replaced:
The rounded rectangle button is deprecated in iOS 7. Instead, use a
system button—that is, a UIButton object of type UIButtonTypeSystem.
iOS 7 system buttons don’t include a bezel or a background appearance.
A system button can contain a graphical symbol or a text title, and it
can specify a tint color or receive its parent’s color.
...
If you need to display a button that includes a bezel, use a button of
type UIButtonTypeCustom and supply a custom background image.
Apple iOS 7 Transition Guide, p. 45, "Rounded Rectangle Button"
So, Apple's recommendation is to use a background image.
Actually in ios 7 the total UI has been changed for basic controls.
If still you want to have a rounded rect button, you have to go for the coregraphical property of UIView subclasses i.e; layer property.
buttonObj.layer.cornerRadius = 5.0f;//any float value
to show the effect you have to give some background color to buttonObj
if you want to set the border width
buttonObj.layer.borderWidth = 2.0f;//any float value
you can also give the color for border
buttonObj.layer.borderColor = [[UIColor greenColor]CGColor];
Note: Here we have to use CGColor for the layers because layers are the core graphical properties of UIViews

how to use different shape of UIButton

I am having below image for UIButton background image.
But UIbutton shape by default is round rect.So touch up inside event will work only in round rect area.
So how can i support touchup inside event for below shape (entire area).
Hope this link helps.
To create an irregular shaped button, you need to create custom button and perform hitTest to check if button was pressed or empty space was pressed.
You can use UIButtonTypeCustom and give the correct frame.

Resources