Created
May 9, 2017 08:16
-
-
Save usagimaru/81b04086d2ba2307f11fbac42e2d7afc to your computer and use it in GitHub Desktop.
UIView extension.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIView { | |
@IBInspectable var borderColor: UIColor? { | |
get { | |
if let c = layer.borderColor { | |
return UIColor(cgColor: c) | |
} | |
return nil | |
} | |
set { | |
layer.borderColor = newValue?.cgColor | |
} | |
} | |
@IBInspectable var borderWidth: CGFloat { | |
get { | |
return layer.borderWidth | |
} | |
set { | |
layer.borderWidth = newValue | |
} | |
} | |
@IBInspectable var cornerRadius: CGFloat { | |
get { | |
return layer.cornerRadius | |
} | |
set { | |
layer.cornerRadius = newValue | |
clipsToBounds = newValue > 0.0 | |
} | |
} | |
func setRoundingCorners(_ rectCorner: UIRectCorner, radius: CGFloat) { | |
let path = UIBezierPath(roundedRect: self.bounds, | |
byRoundingCorners: rectCorner, | |
cornerRadii: CGSize(width: radius, height: radius)) | |
let layer = CAShapeLayer() | |
layer.frame = self.bounds | |
layer.path = path.cgPath | |
self.layer.mask = layer | |
} | |
func resetScrollsToTop(_ targetScrollView: UIScrollView) { | |
if self is UIScrollView { | |
(self as! UIScrollView).scrollsToTop = self == targetScrollView | |
} | |
for v in subviews { | |
v.resetScrollsToTop(targetScrollView) | |
} | |
} | |
func findScrollViews() { | |
if self is UIScrollView { | |
print(#function, "scrollsToTop: \((self as! UIScrollView).scrollsToTop), \(self.hash), \(self.frame)") | |
} | |
for v in subviews { | |
v.findScrollViews() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment