Is it possible to control UIView border properties (color, thickness, etc...) directly from interface builder or I can only do it programmatically?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Xcode: Is there a way to change line spacing (UI L
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
Similar answer to iHulk's one, but in Swift
Add a file named UIView.swift in your project (or just paste this in any file) :
Then this will be available in Interface Builder for every button, imageView, label, etc. in the Utilities Panel > Attributes Inspector :
Note: the border will only appear at runtime.
For Swift 3 and 4, if you're willing to use
IBInspectable
s, there's this:So it is always perfect answer is using the code, Just create IBOutlet instance of the UIView and add the properties
Short answer :
Long answer :
Rounded Corners of UIView/UIButton etc
Border Thickness
Border Color
Please add these 2 simple line of code:
It will work fine.
Rich86Man's answer is correct, but you can use categories to proxy properties such as layer.borderColor. (From the ConventionalC CocoaPod)
CALayer+XibConfiguration.h:
CALayer+XibConfiguration.m:
The result will be apparent during runtime, not in Xcode.
Edit: You also need to set
layer.borderWidth
to at least 1 to see the border with the chosen color.In Swift 2.0:
In Swift 3.0:
If you want to save time, just use two
UIViews
on top of each other, the one at the back being the border color, and the one in front smaller, giving the bordered effect. I don't think this is an elegant solution either, but if Apple cared a little more then you shouldn't have to do this.