{"id":770,"date":"2019-02-19T19:14:23","date_gmt":"2019-02-19T10:14:23","guid":{"rendered":"http:\/\/idealive.jp\/blog\/?p=770"},"modified":"2019-02-19T19:21:09","modified_gmt":"2019-02-19T10:21:09","slug":"%e3%80%90swift%e3%80%91uitextfiled%e3%82%92%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%81%97%e3%81%a6storyboard%e3%81%a7%e8%a8%ad%e5%ae%9a%e3%81%a7%e3%81%8d%e3%82%8b%e3%83%97%e3%83%ad%e3%83%91%e3%83%86","status":"publish","type":"post","link":"https:\/\/idealive.jp\/blog\/2019\/02\/19\/%e3%80%90swift%e3%80%91uitextfiled%e3%82%92%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%81%97%e3%81%a6storyboard%e3%81%a7%e8%a8%ad%e5%ae%9a%e3%81%a7%e3%81%8d%e3%82%8b%e3%83%97%e3%83%ad%e3%83%91%e3%83%86\/","title":{"rendered":"\u3010Swift\u3011UITextFiled\u3092\u30ab\u30b9\u30bf\u30e0\u3057\u3066Storyboard\u3067\u8a2d\u5b9a\u3067\u304d\u308b\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5897\u3084\u3057\u3066\u307f\u308b"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f sohnishi \u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306fSwift\u306b\u3064\u3044\u3066\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>UITextField\u306ecornerRadius\u3084borderWidth\u3001\u3055\u3089\u306bpadding\u306e\u8a2d\u5b9a\u306a\u3069\u3001<\/p>\n<p>Storyboard\u3067\u8a2d\u5b9a\u51fa\u6765\u305f\u3089\u4fbf\u5229\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u3084\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\" title=\"CustomTextField.swift\">import UIKit\r\n\r\n@IBDesignable class CustomTextField: UITextField {\r\n    \r\n    \/\/ \u89d2\u4e38\r\n    @IBInspectable var cornerRadius: CGFloat = 0.0\r\n    \r\n    \/\/ \u67a0\r\n    @IBInspectable var borderColor: UIColor = UIColor.clear\r\n    @IBInspectable var borderWidth: CGFloat = 0.0\r\n    \r\n    \/\/ Padding\r\n    @IBInspectable var paddingTop: CGFloat = 0.0\r\n    @IBInspectable var paddingRight: CGFloat = 0.0\r\n    @IBInspectable var paddingBottom: CGFloat = 0.0\r\n    @IBInspectable var paddingLeft: CGFloat = 0.0\r\n    \r\n    override func draw(_ rect: CGRect) {\r\n        \/\/ \u89d2\u4e38\r\n        self.layer.cornerRadius = cornerRadius\r\n        self.clipsToBounds = (cornerRadius &gt; 0)\r\n        \r\n        \/\/ \u67a0\u7dda\r\n        self.layer.borderColor = borderColor.cgColor\r\n        self.layer.borderWidth = borderWidth\r\n        \r\n        super.draw(rect)\r\n    }\r\n    \r\n    \r\n    override func textRect(forBounds bounds: CGRect) -&gt; CGRect {\r\n        let padding = UIEdgeInsets(top: paddingTop, left: paddingLeft, bottom: paddingBottom, right: paddingRight)\r\n        return bounds.inset(by: padding)\r\n    }\r\n    \r\n    override func placeholderRect(forBounds bounds: CGRect) -&gt; CGRect {\r\n        let padding = UIEdgeInsets(top: paddingTop, left: paddingLeft, bottom: paddingBottom, right: paddingRight)\r\n        return bounds.inset(by: padding)\r\n    }\r\n    \r\n    override func editingRect(forBounds bounds: CGRect) -&gt; CGRect {\r\n        let padding = UIEdgeInsets(top: paddingTop, left: paddingLeft, bottom: paddingBottom, right: paddingRight)\r\n        return bounds.inset(by: padding)\r\n    }\r\n}\r\n<\/pre>\n<p>UITextField\u30af\u30e9\u30b9\u3092\u30b5\u30d6\u30af\u30e9\u30b9\u306b\u6301\u3063\u305fCustomTextField\u30af\u30e9\u30b9\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<p>\u30af\u30e9\u30b9\u540d\u8a18\u8ff0\u306e\u5148\u982d\u306b@IBDesignable\u3068\u8a18\u8ff0\u3059\u308b\u3053\u3068\u3092\u5fd8\u308c\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u8a2d\u5b9a\u3057\u305f\u3044\u5024\u3092\u5909\u6570\u5b9a\u7fa9\u3057\u3001\u5148\u982d\u306b@IBInspectable\u3068\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u3046\u3059\u308b\u3053\u3068\u3067\u3001Storyboard\u3067\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u8a2d\u5b9a\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u6700\u5f8c\u306b\u3001<\/p>\n<p>override func draw(_ rect: CGRect) {}\u5185\u3067\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<p>\u4ee5\u4e0a\u3001sohnishi\u3067\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f sohnishi \u3067\u3059\u3002 \u4eca\u56de\u306fSwift\u306b\u3064\u3044\u3066\u898b\u3066\u3044\u304d\u307e\u3059\u3002 UITextField\u306ecornerRadius\u3084borderWidth\u3001\u3055\u3089\u306bpadding\u306e\u8a2d\u5b9a\u306a\u3069\u3001 Storyboard\u3067\u8a2d\u5b9a\u51fa\u6765\u305f\u3089&#8230;<a class=\"read-more-link button\" href=\"https:\/\/idealive.jp\/blog\/2019\/02\/19\/%e3%80%90swift%e3%80%91uitextfiled%e3%82%92%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%81%97%e3%81%a6storyboard%e3%81%a7%e8%a8%ad%e5%ae%9a%e3%81%a7%e3%81%8d%e3%82%8b%e3%83%97%e3%83%ad%e3%83%91%e3%83%86\/\">\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":3,"featured_media":772,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-770","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-swift"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts\/770"}],"collection":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/comments?post=770"}],"version-history":[{"count":1,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts\/770\/revisions"}],"predecessor-version":[{"id":771,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/posts\/770\/revisions\/771"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/media\/772"}],"wp:attachment":[{"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/media?parent=770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/categories?post=770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idealive.jp\/blog\/wp-json\/wp\/v2\/tags?post=770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}