UIView.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (C) 2016 Inigo Valentin
  2. //
  3. // This file is part of the Gasteizko Margolariak IOS app.
  4. //
  5. // The Gasteizko Margolariak IOS app is free software: you can
  6. // redistribute it and/or modify it under the terms of the
  7. // GNU General Public License as published by the Free Software
  8. // Foundation, either version 3 of the License, or (at your
  9. // option) any later version.
  10. //
  11. // The Gasteizko Margolariak IOS app is distributed in the
  12. // hope that it will be useful, but WITHOUT ANY WARRANTY;
  13. // without even the implied warranty of MERCHANTABILITY or
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  15. // Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public
  18. // License along with the Gasteizko Margolariak IOS app.
  19. // If not, see <http://www.gnu.org/licenses/>.
  20. import UIKit
  21. /**
  22. Extension of UIView that adds some options at the interface
  23. builder.
  24. */
  25. @IBDesignable extension UIView {
  26. //Border color.
  27. @IBInspectable var borderColor:UIColor? {
  28. set {
  29. layer.borderColor = newValue!.cgColor
  30. }
  31. get {
  32. if let color = layer.borderColor {
  33. return UIColor(cgColor:color)
  34. }
  35. else {
  36. return nil
  37. }
  38. }
  39. }
  40. //Border width.
  41. @IBInspectable var borderWidth:CGFloat {
  42. set {
  43. layer.borderWidth = newValue
  44. }
  45. get {
  46. return layer.borderWidth
  47. }
  48. }
  49. @IBInspectable var cornerRadius:CGFloat {
  50. set {
  51. layer.cornerRadius = newValue
  52. clipsToBounds = newValue > 0
  53. }
  54. get {
  55. return layer.cornerRadius
  56. }
  57. }
  58. }