How to create border in UIButton?

uibutton border storyboard
add border to uibutton swift
add border to uiview swift storyboard
add bottom border to uibutton swift
how to add a border to a view in swift
add border to stackview swift
uitextview border
uilabel border storyboard

I use custom button in my app named "addButton" and I want to border it with white color how can i get the white color border around my custom button?

You can set the border properties on the CALayer by accessing the layer property of the button.

First, add Quartz

#import <QuartzCore/QuartzCore.h>

Set properties:

myButton.layer.borderWidth = 2.0f;
myButton.layer.borderColor = [UIColor greenColor].CGColor;


The CALayer in the link above allows you to set other properties like corner radius, maskToBounds etc...

Also, a good article on button fun:

Add a border to a UIButton. Original code, add a border, corner radius, and a shadow to any UIView, UIButton, During my iOS work, I've assembled a set of code that I bring with me� Here you can create dynamically a UIButton: //For button image UIImage *closebtnimg = [UIImage imageNamed:@"close_btn.png"]; //Custom type button btnclose = [[UIButton buttonWithType:UIButtonTypeCustom]retain]; //Set frame of button means position btnclose.frame = CGRectMake(103, 257, 94, 32); //Button with 0 border so it's shape like image shape [btnclose.layer setBorderWidth:0]; //Set title

Swift: Adding a Border, Corner Radius, and Shadow to a UIView, To give border color to uibutton :-1. take uibutton as property .2. give corner radius and corner width to uibutton.3. now give border color to uibutton.for swift use� I want to create Custom UIButton with rectangular shape. for this I am using rectangular view as a Background for UIButton and making UIbuttons background colour as clearcolor. But border of UIbutton still remains. any suggestions on how to make border disappear? Thanks for any help in advance..

And in swift, you don't need to import "QuartzCore/QuartzCore.h"

Just use:

button.layer.borderWidth = 0.8
button.layer.borderColor = (UIColor( red: 0.5, green: 0.5, blue:0, alpha: 1.0 )).cgColor


button.layer.borderWidth = 0.8
button.layer.borderColor = UIColor.grayColor().cgColor

How to give border color to UIButton in objc and Swift., Double click the button to edit button text as below picture. display xcode ui elements library and search and use ui button. 3. How To Make The� Add the border-radius property to create rounded outline buttons: Example.btn { border-radius: 5px;} Try it Yourself »

The problem setting the layer's borderWidth and borderColor is that the when you touch the button the border doesn't animate the highlight effect.

Of course, you can observe the button's events and change the border color accordingly but that feels unnecessary.

Another option is to create a stretchable UIImage and setting it as the button's background image. You can create an Image set in your Images.xcassets like this:

Then, you set it as the button's background image:

If your image is a template image you can set tint color of the button and the border will change:

Now the border will highlight with the rest of the button when touched.

How To Make Rounded Border Button In Swift, All UIView subclasses have a built-in way to draw a border around them using their underlying CALayer . For example, to draw a 10-point red� This example will tell you how to create a rounded border button in swift. It will also tell you how to align button in iOS app main screen, how to set button background color, how to set button width and height etc. 1. Rounded Border Button Example UI. First let us look at the example execution screen as below picture.

To change button Radius, Color and Width I set like this:

self.myBtn.layer.cornerRadius = 10;
self.myBtn.layer.borderWidth = 1;
self.myBtn.layer.borderColor =[UIColor colorWithRed:189.0/255.0f green:189.0/255.0f blue:189.0/255.0f alpha:1.0].CGColor;

How to add a border outline color to a UIView, Welcome to UIButtons Trick! Learn the easy way to Add Border , Shadow , Image Icon to Duration: 11:34 Posted: Mar 11, 2018 I have a rectangle image (jpg) and want to use it to fill the background of a button with rounded corner in xcode. I wrote the following: UIButton *button = [[UIButton buttonWithType:

IOS 11, Swift 4 : How To Add Border, Shadow and Image Icon to , AFAIK (at least, that's how I would try it), you should subclass the UIButton, define an IBDesignable property to set the border width. You'll find details on how to� How can I make a UIButton border to look alike in the below image (the "Getting Started") button with a transparent background? How should I achieve this using storyboard or how to do it

Button borders in IB, // Custom Border to the UIButton private let border = CAShapeLayer() override func draw(_ rect: CGRect) { // Our custom drawing code will go� You can use CSS3 to draw borders around any HTML5 element. You have some freedom in the border size, style, and color. Here are two ways to define border properties: using individual border attributes, and using a shortcut. Borders don’t actually change the layout, but they do add visual separation that can be appealing, especially …

Create a Custom UIButton With States, Add a border to a UIButton. Original code, UIButton+Border.swift. import Foundation. import UIKit. public enum UIButtonBorderSide {. case Top, Bottom, Left,� Create a custom border in Publisher using your chosen clip art picture. Although you don't have as much control over spacing, this is a lot quicker! Insert a text box of the desired size (this may take some trial and error) and apply the custom border to it. Then select the text box, right-click, and choose Save as Picture.

  • possible duplicate of Add border and shadow to the buttons
  • Make sure you link your target to the QuartCore framework in the Build Phases tab of the target editor.
  • Do I need to import quartz ? I can still access layer of button without it. My purpose of asking is : what benefits are we getting when importing Quartz
  • plus 1 for using CGColor
  • According to XCode 9, "CGColor has been renamed cgColor".
  • What do you make the Image out of?
  • To make that image I used Sketch, but you can use Gimp, Illustrator, Photoshop...
  • Nice answer. It's better than change layer's borderWidth.
  • I've problems with the constraints over swift 4,I did full size button ( side to side in the width) , In the xcode I saw border preview very well, but over the emulator or device I saw the border reduced to the size of the text inside of button, The only autolayout constraint that I added was the centered horizontally , how fix it? thanks!
  • @CristianChaparroA. The reason is that prepareForInterfaceBuilder only gets called from IB, not when you run the app. So also set the UIEdgeInsets in awakeFromNib, then it will show also when running the app.
  • button.layer.borderColor = UIColor.gray.cgColor is acceptable too!