{"id":289,"date":"2020-09-02T11:27:26","date_gmt":"2020-09-02T02:27:26","guid":{"rendered":"https:\/\/naoya-ono.com\/swift\/?p=289"},"modified":"2020-09-15T12:40:58","modified_gmt":"2020-09-15T03:40:58","slug":"uitextfield-placeholder","status":"publish","type":"post","link":"https:\/\/naoya-ono.com\/swift\/uitextfield-placeholder\/","title":{"rendered":"\u3010Swift\u3011UITextField\u306ePlaceholder\u3092\u88c5\u98fe\u65b9\u6cd5\uff01\u592a\u5b57\u3001\u8272\u3001\u30b5\u30a4\u30ba\u306a\u3069"},"content":{"rendered":"<p>  <a class=\"reference table\" href=\"http:\/\/URL\" rel=\"noopener noreferrer\"><br \/>\n    <span class=\"tbcell refttl\">\u53c2\u8003<\/span><br \/>\n    <span class=\"tbcell refcite\">\u30da\u30fc\u30b8\u30bf\u30a4\u30c8\u30eb<span>\u30b5\u30a4\u30c8\u540d<\/span><\/span><br \/>\n  <\/a>\u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306eplaceholder\u306e\u8272\u3084\u3001\u30b5\u30a4\u30ba\u306e\u5909\u66f4\u306f<span>NSAttributedString\u3092\u4f7f\u3046\u3053\u3068\u3067\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\n<div class=\"memo \">\n<div class=\"memo_ttl dfont\"> NSAttributedString\u3068\u306f\uff1f<\/div>\n<p><span>NSAttributedString\u306f\u30c6\u30ad\u30b9\u30c8\uff08\u6587\u5b57\u5217\uff09\u3092\u88c5\u98fe\u3059\u308b\u305f\u3081\u306e\u30af\u30e9\u30b9\u306e\u3053\u3068\u3092\u6307\u3057\u307e\u3059\u3002<\/span><\/p>\n<\/div>\n<h2 class=\"hh hh5 pastel-bc\" id=\"i-0\"><span>NSAttributedString\u3092\u4f7f\u3063\u3066placeholder\u3092\u88c5\u98fe\u3059\u308b<\/span><\/h2>\n<p>NSAttributedString\u3092\u4f7f\u3063\u3066\u88c5\u98fe\u3057\u305f\u3044\u5834\u5408\u306f\u6b21\u306e\u3088\u3046\u306b\u66f8\u304d\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code><span class=\"s7\">textField<\/span>.<span class=\"s4\">attributedPlaceholder<\/span> = <span class=\"s3\">NSAttributedString<\/span>(string: <span class=\"s8\">\"placeholder\u306b\u8868\u793a\u3059\u308b\u6587\u8a00\"<\/span>, attributes: \u88c5\u98fe\u3059\u308b\u5185\u5bb9)<\/code><\/pre>\n<\/div>\n<p>\u4e0a\u8a18\u306e\u300c\u88c5\u98fe\u3059\u308b\u5185\u5bb9\u300d\u306e\u3068\u3053\u308d\u306b\u30d5\u30a9\u30f3\u30c8\u3084\u8272\u306a\u3069\u3092\u66f8\u3044\u3066\u3044\u304f\u306e\u3067\u3059\u304c\u3001\u9577\u304f\u306a\u308b\u306e\u3067\u5909\u6570\u306b\u5165\u308c\u3066\u3001\u305d\u308c\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3068\u826f\u3044\u3067\u3059\u3002<\/p>\n<p>\u66f8\u304d\u65b9\u306f\u6b21\u306e\u901a\u308a\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>\/\/ \u88c5\u98fe\u3059\u308b\u5185\u5bb9\nlet attributes: [NSAttributedString.Key : Any] = [\n  .font : UIFont.systemFont(ofSize: 18.0), \/\/ \u6587\u5b57\u30b5\u30a4\u30ba\n  .foregroundColor : UIColor.red \/\/ \u6587\u5b57\u8272\n]<\/code><\/pre>\n<\/div>\n<p>\u8f9e\u66f8\u578b\u306a\u306e\u3067\u3001\u30b5\u30a4\u30ba\u3084\u3089\u8272\u3084\u3089\u3092\u4e00\u5ea6\u306b\u8a2d\u5b9a\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><script src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\" async><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-4166043434922569\" data-ad-slot=\"7750996733\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h2 class=\"hh hh5 pastel-bc\" id=\"i-1\"><span>\u5b9f\u88c5\u4f8b<\/span><\/h2>\n<p>\u6b21\u306e\u3088\u3046\u306b\u66f8\u304f\u3068\u3001\u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306eplaceholder\u3060\u3051\u3001\u592a\u5b57\u3067\u8272\u304clightGray\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>class ViewController: UIViewController, UITableViewDataSource {\n\n  @IBOutlet weak var textField: UITextField!\n\n  override func viewDidLoad() {\n    super.viewDidLoad()\n  \n    let attributes: [NSAttributedString.Key : Any] = [\n      .font: UIFont.boldSystemFont(ofSize: 20.0), \/\/ \u30d5\u30a9\u30f3\u30c8\u30b5\u30a4\u30ba\uff1a20\u3001\u592a\u3055\uff1abold\n      .foregroundColor : UIColor.lightGray \/\/ \u30ab\u30e9\u30fc\n    ]\n\n    textField.attributedPlaceholder = NSAttributedString(string: \"\u30ab\u30c6\u30b4\u30ea\u30fc\u3092\u8ffd\u52a0\", attributes: attributes)\n  }\n}<\/code><\/pre>\n<\/div>\n<p>\u8a2d\u5b9a\u524d\u3068\u8a2d\u5b9a\u5f8c\u306e\u753b\u9762\u306f\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><span class=\"labeltext accent-bc\" style=\"font-size: 12pt;\"><strong>&nbsp;\u8a2d\u5b9a\u524d&nbsp;<\/strong><\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/placeholder-setting1.png\" alt=\"\" width=\"738\" height=\"154\" class=\"alignnone wp-image-293 size-full\" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/placeholder-setting1.png 738w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/placeholder-setting1-300x63.png 300w\" sizes=\"(max-width: 738px) 100vw, 738px\"><\/p>\n<p><span class=\"labeltext accent-bc\" style=\"font-size: 12pt;\"><strong>&nbsp;\u8a2d\u5b9a\u5f8c&nbsp;<\/strong><\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/placeholder-setting2.png\" alt=\"\" width=\"740\" height=\"130\" class=\"alignnone wp-image-292 size-full\" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/placeholder-setting2.png 740w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/placeholder-setting2-300x53.png 300w\" sizes=\"(max-width: 740px) 100vw, 740px\"><\/p>\n<p>\u6587\u5b57\u304c\u5927\u304d\u304f\u3001\u305d\u3057\u3066\u592a\u304f\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306eplaceholder\u306e\u8272\u3084\u3001\u30b5\u30a4\u30ba\u306e\u5909\u66f4\u306fNSAttributedString\u3092\u4f7f\u3046\u3053\u3068\u3067\u3067\u304d\u307e\u3059\u3002 NSAttributedString\u3092\u4f7f\u3063\u3066placeholder\u3092\u88c5\u98fe\u3059\u308b NSAttribu &#8230; <\/p>\n","protected":false},"author":1,"featured_media":291,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,13],"tags":[],"_links":{"self":[{"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/posts\/289"}],"collection":[{"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/comments?post=289"}],"version-history":[{"count":7,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/posts\/289\/revisions"}],"predecessor-version":[{"id":1317,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/posts\/289\/revisions\/1317"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/media\/291"}],"wp:attachment":[{"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/media?parent=289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/categories?post=289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/tags?post=289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}