

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How To Change UIView's Border Color And Thickness in Cocoa Touch?
In this article we'll learn how to change a View's border color and thickness.
This can be done in two ways as mentioned below.
Method 1 − Writing the code
Let's suppose we have a view name backView, then to add a border color and thickness we can write
backView.layer.borderWidth = 5 // Or any integer value
backView.layer.bordercolor = colorLiteral(red: 0.09019608051, green: 0, blue: 0.3019607961, alpha: 1) this code will add a border of 5 width and a dark blue color. Below is the output is produces.
Method 2 − Creating an extension of UIView with designable and inspectable
@IBDesignable class DesignableView: UIView { } extension UIView { @IBInspectable var borderWidth: CGFloat { get { return layer.borderWidth } set { layer.borderWidth = newValue } } @IBInspectable var borderColor: UIColor? { get { if let color = layer.borderColor { return UIColor(cgColor: color) } return nil } set { if let color = newValue { layer.borderColor = color.cgColor } else { layer.borderColor = nil } } } }
The above will create an editable Storyboard, which will render live changes on the storyboard when edited from the attribute inspector.
Below is the output for method 2 showing how it renders live on storyboard.
- Related Questions & Answers
- How to change the thickness of a shape's outline on a Tkinter canvas?
- How to change an HTML5 input's placeholder color with CSS?
- How to set the border color of the dots in matplotlib's scatterplots?
- How to create a Border, Border radius, and shadow to a UIView in iPhone/iOS?
- How to change the menu background color of Tkinter's OptionMenu widget?
- What's the best way to detect a 'touch screen' device using JavaScript?
- Change the color of top border with CSS
- Change the color of right border with CSS
- Why should a religion bestow power to touch girl's genitals?
- How to change JTable's header font in Java
- How to set border width, border style, and border color in one declaration with JavaScript?
- How to change the plot border color of a ggplot2 graph in R?
- Change the color of the bottom border with CSS
- Change the color of the left border with CSS
- How to change a table's fontsize with matplotlib.pyplot?
Advertisements