在xCode 6.1中创建UITextField的通用填充/插图(Swift)

问题描述:

如何在swift中为文本字段(UITextField)创建填充?我希望它是全球范围,所以当UIView加载每个文本字段有这个填充适用于它。在xCode 6.1中创建UITextField的通用填充/插图(Swift)

当前银行代码:

class MyCustomTextField: UITextField { 
// Custom Code that i can't figure out. 
} 

步骤我尝试采取:

  • 苹果开发者文档,它不谈论插图或填充 覆盖
  • 搜索Stackoverflow并且看到它们或者与objective-c相关,或者 黑客在Xc被移除时颂成为6.1
  • 谷歌,一无所获约斯威夫特填充(仅目标c)

谢谢你在先进。
Swift初学者:)

class MyCustomTextField : UITextField { 
    var leftMargin : CGFloat = 10.0 

    override func textRectForBounds(bounds: CGRect) -> CGRect { 
     var newBounds = bounds 
     newBounds.origin.x += leftMargin 
     return newBounds 
    } 

    override func editingRectForBounds(bounds: CGRect) -> CGRect { 
     var newBounds = bounds 
     newBounds.origin.x += leftMargin 
     return newBounds 
    } 
}