{"id":7478,"date":"2025-05-30T13:44:33","date_gmt":"2025-06-05T05:59:32","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7478"},"modified":"2025-06-05T13:44:33","modified_gmt":"2025-06-05T05:59:32","slug":"https-badgameshow-com-steven-409","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-409\/","title":{"rendered":"Swift \u81ea\u52d5\u6392\u7248 UITextView \u5b8c\u6574\u6559\u5b78\uff1a2025 \u6700\u65b0\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, UITextView, \u81ea\u52d5\u6392\u7248, Swift \u6559\u5b78, iOS \u958b\u767c\"><\/p>\n<h1>Swift \u81ea\u52d5\u6392\u7248 UITextView \u5b8c\u6574\u6559\u5b78\uff1a2025 \u6700\u65b0\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10<\/h1>\n<p>\u5728 iOS \u958b\u767c\u4e2d\uff0cSwift \u63d0\u4f9b\u4e86\u4e00\u500b\u5f37\u5927\u7684\u63a7\u4ef6\u2014\u2014<strong>UITextView<\/strong>\uff0c\u8b93\u958b\u767c\u8005\u80fd\u5920\u8f15\u9b06\u5be6\u73fe\u6587\u5b57\u5167\u5bb9\u7684\u81ea\u52d5\u6392\u7248\u3002\u9019\u4e0d\u50c5\u80fd\u63d0\u5347\u61c9\u7528\u7684\u7f8e\u89c0\u6027\uff0c\u9084\u80fd\u589e\u5f37\u7528\u6236\u9ad4\u9a57\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528 UITextView \u5be6\u73fe\u81ea\u52d5\u6392\u7248\uff0c\u4e26\u63d0\u4f9b\u6700\u4f73\u5be6\u8e10\u548c\u793a\u4f8b\u4ee3\u78bc\u3002<\/p>\n<h2>\u70ba\u4ec0\u9ebc\u9078\u64c7 UITextView\uff1f<\/h2>\n<p>UITextView \u662f\u4e00\u500b\u53ef\u6efe\u52d5\u7684\u591a\u884c\u6587\u672c\u6846\uff0c\u652f\u63f4\u8c50\u5bcc\u7684\u6587\u672c\u683c\u5f0f\uff0c\u4e26\u63d0\u4f9b\u4e86\u81ea\u52d5\u6392\u7248\u7684\u529f\u80fd\uff0c\u80fd\u5920\u6839\u64da\u5167\u5bb9\u81ea\u52d5\u8abf\u6574\u986f\u793a\u6548\u679c\u3002\u9019\u5c0d\u65bc\u9700\u8981\u5c55\u793a\u5927\u91cf\u6587\u672c\u7684\u61c9\u7528\u5c24\u70ba\u91cd\u8981\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 UITextView \u4f86\u5be6\u73fe\u81ea\u52d5\u6392\u7248<\/h2>\n<p>\u8981\u5728 Swift \u4e2d\u4f7f\u7528 UITextView \u9032\u884c\u81ea\u52d5\u6392\u7248\uff0c\u8acb\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\u5728 Xcode \u4e2d\u5275\u5efa\u4e00\u500b\u65b0\u7684\u5c08\u6848\u3002<\/li>\n<li>\u5728\u4ecb\u9762\u69cb\u5efa\u5668\u4e2d\u62d6\u653e\u4e00\u500b UITextView \u63a7\u4ef6\u5230\u60a8\u7684\u8996\u5716\u4e2d\u3002<\/li>\n<li>\u9023\u63a5 UITextView \u5230\u60a8\u7684 ViewController \u985e\u5225\uff0c\u4e26\u5728\u4ee3\u78bc\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5c6c\u6027\u8a2d\u5b9a\uff1a<\/li>\n<\/ol>\n<pre><code class=\"language-swift line-numbers\">import UIKit\n\nclass ViewController: UIViewController {\n    @IBOutlet weak var textView: UITextView!\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \/\/ \u8a2d\u5b9a\u81ea\u52d5\u6392\u7248\n        textView.textContainer.lineFragmentPadding = 0\n        textView.textContainerInset = .zero\n        textView.text = \"\u9019\u662f\u4f7f\u7528 UITextView \u5be6\u73fe\u81ea\u52d5\u6392\u7248\u7684\u7bc4\u4f8b\u6587\u5b57\u3002\"\n    }\n}\n<\/code><\/pre>\n<h2>\u5e38\u898b\u554f\u984c\u53ca\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u4f7f\u7528 UITextView \u9032\u884c\u81ea\u52d5\u6392\u7248\u6642\uff0c\u60a8\u53ef\u80fd\u6703\u9047\u5230\u4ee5\u4e0b\u554f\u984c\uff1a<\/p>\n<ul>\n<li><strong>\u6587\u5b57\u5167\u5bb9\u4e0d\u986f\u793a\uff1a<\/strong>\u78ba\u4fdd UITextView \u7684 frame \u5927\u5c0f\u5408\u9069\uff0c\u4e26\u4e14\u5df2\u6b63\u78ba\u8a2d\u5b9a IBOutlet\u3002<\/li>\n<li><strong>\u5167\u5bb9\u8d85\u51fa\u7bc4\u570d\uff1a<\/strong>\u6aa2\u67e5 textView \u7684\u5c6c\u6027\uff0c\u78ba\u4fdd\u884c\u9593\u8ddd\u548c\u908a\u8ddd\u8a2d\u5b9a\u5408\u7406\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u60a8\u53ef\u4ee5\u9032\u4e00\u6b65\u64f4\u5c55 UITextView \u7684\u529f\u80fd\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u52a0\u5165\u5bcc\u6587\u672c\u683c\u5f0f\u5316\uff0c\u4f7f\u7528 <code>NSAttributedString<\/code> \u4f86\u589e\u5f37\u6587\u672c\u986f\u793a\u6548\u679c\u3002<\/li>\n<li>\u6dfb\u52a0\u6587\u5b57\u81ea\u52d5\u6aa2\u67e5\u548c\u9ad8\u4eae\u529f\u80fd\uff0c\u63d0\u5347\u7528\u6236\u4ea4\u4e92\u9ad4\u9a57\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u81ea\u52d5\u6392\u7248-UITextView_1675476509.0026119.webp\" alt=\"Swift \u81ea\u52d5\u6392\u7248 UITextView\" title=\"Swift \u81ea\u52d5\u6392\u7248, UITextView, methods(), \u81ea\u52d5\u6392\u7248, \u6587\u5b57\u7f8e\u89c0\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u4f7f\u7528 UITextView \u9032\u884c\u81ea\u52d5\u6392\u7248\u662f\u4e00\u500b\u7c21\u55ae\u800c\u6709\u6548\u7684\u89e3\u6c7a\u65b9\u6848\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u63d0\u5347\u61c9\u7528\u7684\u53ef\u8b80\u6027\u548c\u7f8e\u89c0\u6027\u3002\u672c\u6587\u4ecb\u7d39\u7684\u7bc4\u4f8b\u4ee3\u78bc\u548c\u6700\u4f73\u5be6\u8e10\u5c07\u5e6b\u52a9\u60a8\u5728\u958b\u767c\u4e2d\u66f4\u597d\u5730\u5229\u7528\u9019\u500b\u63a7\u4ef6\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>1. UITextView \u80fd\u5426\u652f\u6301\u5bcc\u6587\u672c\u683c\u5f0f\uff1f<\/h3>\n<p>\u662f\u7684\uff0cUITextView \u652f\u6301\u4f7f\u7528 <code>NSAttributedString<\/code> \u4f86\u5275\u5efa\u5bcc\u6587\u672c\u5167\u5bb9\u3002<\/p>\n<h3>2. \u5982\u4f55\u8a2d\u5b9a UITextView \u7684\u5b57\u9ad4\u8207\u984f\u8272\uff1f<\/h3>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528 textView \u7684 <code>font<\/code> \u548c <code>textColor<\/code> \u5c6c\u6027\u4f86\u8a2d\u5b9a\u5b57\u9ad4\u548c\u984f\u8272\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">textView.font = UIFont.systemFont(ofSize: 16)\ntextView.textColor = UIColor.black\n<\/code><\/pre>\n<h3>3. UITextView \u6709\u7121\u81ea\u52d5\u6efe\u52d5\u529f\u80fd\uff1f<\/h3>\n<p>UITextView \u672c\u8eab\u652f\u63f4\u6efe\u52d5\uff0c\u60a8\u53ef\u4ee5\u8a2d\u5b9a <code>isScrollEnabled<\/code> \u5c6c\u6027\u4f86\u63a7\u5236\u6efe\u52d5\u529f\u80fd\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:\u4e86\u89e3\u5982\u4f55\u4f7f\u7528Swift\u8a9e\u8a00\u4f86\u81ea\u52d5\u6392\u7248UITextView\uff0c\u53ef\u4ee5\u8b93\u4f60\u7684\u6587\u5b57\u66f4\u52a0\u7f8e\u89c0\uff0c\u4e26\u4e14\u66f4\u5bb9\u6613\u95b1\u8b80\u3002\u672c\u6587\u5c07\u4ecb\u7d39Swift\u4e2d\u7684methods()\u51fd\u6578\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u4f86\u81ea\u52d5\u6392\u7248UITextView\u3002<\/p>\n","protected":false},"author":1,"featured_media":7476,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[174,5],"tags":[173,9],"class_list":["post-7478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u81ea\u52d5\u6392\u7248-UITextView_1675476509.0026119.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1WC","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=7478"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7478\/revisions"}],"predecessor-version":[{"id":13434,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7478\/revisions\/13434"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7476"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}