加大 UITextField的点击范围实现代码如下:
1 class UITextFieldEx : UITextField { 2 3 @IBInspectable 4 var localPlaceholder: String? { 5 didSet { 6 if let text = localPlaceholder { 7 self.placeholder = NSLocalizedString(text, comment: text) 8 } 9 } 10 } 11 12 } 13 14 class UITextFieldPointInside : UITextFieldEx { 15 16 override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool { 17 var bounds = self.bounds 18 let widthDelta = max(44.0 - bounds.size.width, 0) 19 let heightDelta = max(44.0 - bounds.size.height, 0) 20 bounds = CGRectInset(bounds, -4 * widthDelta, -4 * heightDelta) 21 return CGRectContainsPoint(bounds, point) 22 } 23 24 }
加大UIButton的 代码类似如下
1 class UIButtonEx : UIButton { 2 3 4 @IBInspectable 5 var localTitle: String? { 6 didSet { 7 if let text = localTitle { 8 self.setTitle(NSLocalizedString(text, comment: text), forState: UIControlState.Normal) 9 } 10 } 11 } 12 13 14 } 15 16 class UIButtonPointInside : UIButtonEx { 17 18 override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool { 19 var bounds = self.bounds 20 let widthDelta = max(44.0 - bounds.size.width, 0) 21 let heightDelta = max(44.0 - bounds.size.height, 0) 22 bounds = CGRectInset(bounds, -0.5 * widthDelta, -0.5 * heightDelta) 23 return CGRectContainsPoint(bounds, point) 24 } 25 26 }
参考链接如下:
http://my.oschina.net/gejw0623/blog/362303