{"id":7392,"date":"2025-06-04T13:02:51","date_gmt":"2025-06-05T05:18:50","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7392"},"modified":"2025-06-05T13:02:51","modified_gmt":"2025-06-05T05:18:50","slug":"https-badgameshow-com-steven-367","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-367\/","title":{"rendered":"Swift \u6587\u5b57\u81ea\u9069\u61c9\u9ad8\u5ea6\u7684\u5be6\u4f5c\u8207\u6700\u4f73\u5be6\u8e10\uff082025 \u6700\u65b0\u6559\u5b78\uff09"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, \u6587\u5b57\u81ea\u9069\u61c9\u9ad8\u5ea6, UITextView, iOS\u958b\u767c\"><\/p>\n<h2>Swift \u6587\u5b57\u81ea\u9069\u61c9\u9ad8\u5ea6\u7684\u6982\u5ff5<\/h2>\n<p>Swift \u662f\u4e00\u7a2e\u73fe\u4ee3\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u5c08\u70ba iOS \u548c macOS \u61c9\u7528\u7a0b\u5f0f\u7684\u958b\u767c\u800c\u8a2d\u8a08\u3002\u5728\u61c9\u7528\u7a0b\u5f0f\u958b\u767c\u4e2d\uff0c\u6587\u5b57\u6846\u7684\u9ad8\u5ea6\u81ea\u52d5\u8abf\u6574\u662f\u4e00\u500b\u91cd\u8981\u529f\u80fd\uff0c\u80fd\u5920\u63d0\u5347\u4f7f\u7528\u8005\u9ad4\u9a57\u3002\u9019\u9805\u529f\u80fd\u4f7f\u5f97\u958b\u767c\u8005\u4e0d\u5fc5\u624b\u52d5\u8abf\u6574\u6587\u5b57\u6846\u7684\u9ad8\u5ea6\uff0c\u4e26\u78ba\u4fdd\u4efb\u4f55\u9577\u5ea6\u7684\u6587\u5b57\u90fd\u80fd\u5b8c\u6574\u986f\u793a\u3002<\/p>\n<h2>\u5982\u4f55\u5728 Swift \u4e2d\u5be6\u73fe\u6587\u5b57\u81ea\u9069\u61c9\u9ad8\u5ea6<\/h2>\n<p>\u5728 Swift \u4e2d\u5be6\u73fe\u6587\u5b57\u81ea\u9069\u61c9\u9ad8\u5ea6\uff0c\u901a\u5e38\u4f7f\u7528 <code>UITextView<\/code> \u985e\u5225\u3002\u4ee5\u4e0b\u662f\u5be6\u73fe\u7684\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li>\u9996\u5148\uff0c\u5275\u5efa\u4e00\u500b <code>UITextView<\/code> \u5be6\u4f8b\u3002<\/li>\n<li>\u8a2d\u7f6e\u5176 <code>isScrollEnabled<\/code> \u5c6c\u6027\u70ba <code>false<\/code>\uff0c\u4ee5\u5141\u8a31\u9ad8\u5ea6\u81ea\u52d5\u8abf\u6574\u3002<\/li>\n<li>\u4f7f\u7528\u81ea\u52d5\u4f48\u5c40\u7d04\u675f\u4f86\u8a2d\u5b9a\u6587\u5b57\u6846\u7684\u908a\u754c\uff0c\u78ba\u4fdd\u5b83\u80fd\u6839\u64da\u5167\u5bb9\u81ea\u52d5\u64f4\u5c55\u3002<\/li>\n<\/ol>\n<p>\u4ee5\u4e0b\u662f\u793a\u7bc4\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">import UIKit\n\nclass ViewController: UIViewController {\n    let textView = UITextView()\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \n        setupTextView()\n    }\n    \n    func setupTextView() {\n        textView.isScrollEnabled = false\n        textView.translatesAutoresizingMaskIntoConstraints = false\n        textView.text = \"\u9019\u662f\u4e00\u6bb5\u793a\u7bc4\u6587\u5b57\uff0c\u6703\u81ea\u52d5\u8abf\u6574\u9ad8\u5ea6\u4ee5\u9069\u61c9\u5167\u5bb9\u3002\"\n        \n        view.addSubview(textView)\n        \n        NSLayoutConstraint.activate([\n            textView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),\n            textView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20),\n            textView.topAnchor.constraint(equalTo: view.topAnchor, constant: 100)\n        ])\n    }\n}\n<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664\u6307\u5357<\/h2>\n<p>\u5728\u5be6\u4f5c\u904e\u7a0b\u4e2d\uff0c\u60a8\u53ef\u80fd\u6703\u9047\u5230\u4ee5\u4e0b\u5e38\u898b\u554f\u984c\uff1a<\/p>\n<ul>\n<li><strong>\u554f\u984c\uff1a<\/strong>\u6587\u5b57\u6846\u4e0d\u81ea\u52d5\u8abf\u6574\u9ad8\u5ea6\u3002<\/li>\n<li><strong>\u89e3\u6c7a\u65b9\u6848\uff1a<\/strong>\u78ba\u4fdd\u60a8\u5df2\u6b63\u78ba\u8a2d\u7f6e <code>isScrollEnabled<\/code> \u5c6c\u6027\u70ba <code>false<\/code>\uff0c\u4e26\u6aa2\u67e5\u81ea\u52d5\u4f48\u5c40\u7d04\u675f\u662f\u5426\u6b63\u78ba\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u60a8\u53ef\u4ee5\u5c07\u6b64\u6280\u8853\u64f4\u5c55\u5230\u5176\u4ed6 UI \u5143\u7d20\uff0c\u4f8b\u5982 <code>UILabel<\/code>\uff0c\u901a\u904e\u8a08\u7b97\u6587\u672c\u7684\u5927\u5c0f\u4f86\u52d5\u614b\u6539\u8b8a\u5176\u9ad8\u5ea6\u3002\u6b64\u5916\uff0c\u8003\u616e\u7d50\u5408\u4f7f\u7528 <code>Auto Layout<\/code> \u6216 <code>SwiftUI<\/code> \u4f86\u5be6\u73fe\u66f4\u9748\u6d3b\u7684\u754c\u9762\u8a2d\u8a08\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u6587\u5b57\u81ea\u9069\u61c9\u9ad8\u5ea6-\ud83d\udcdd\ud83d\udcbb_1675475190.8040378.webp\" alt=\"Swift \u6587\u5b57\u81ea\u9069\u61c9\u9ad8\u5ea6\u793a\u7bc4\" title=\"Swift \u6587\u5b57\u81ea\u9069\u61c9\u9ad8\u5ea6\u5be6\u4f5c\u793a\u7bc4\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>Q1: UITextView \u5982\u4f55\u81ea\u52d5\u8a08\u7b97\u9ad8\u5ea6\uff1f<\/h3>\n<p>A1: UITextView \u53ef\u4ee5\u6839\u64da\u5176\u5167\u5bb9\u81ea\u52d5\u8a08\u7b97\u9ad8\u5ea6\uff0c\u524d\u63d0\u662f <code>isScrollEnabled<\/code> \u5fc5\u9808\u8a2d\u70ba <code>false<\/code> \u4e26\u6b63\u78ba\u8a2d\u7f6e Auto Layout \u7d04\u675f\u3002<\/p>\n<h3>Q2: \u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528 Auto Layout\uff1f<\/h3>\n<p>A2: \u4f7f\u7528 <code>NSLayoutConstraint<\/code> \u8a2d\u7f6e\u7d04\u675f\u4ee5\u78ba\u4fdd UI \u5143\u7d20\u6839\u64da\u5167\u5bb9\u81ea\u52d5\u8abf\u6574\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:Swift\u6587\u5b57\u81ea\u9069\u61c9\u9ad8\u5ea6\u662f\u4e00\u500b\u5f88\u6709\u7528\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u8b93\u4f60\u7684\u6587\u5b57\u81ea\u52d5\u8abf\u6574\u9ad8\u5ea6\uff0c\u4ee5\u9069\u61c9\u4e0d\u540c\u7684\u87a2\u5e55\u5c3a\u5bf8\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u4e2d\u7684methods()\u51fd\u6578\u4f86\u5be6\u73fe\u6587\u5b57\u81ea\u9069\u61c9\u9ad8\u5ea6\u7684\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":7391,"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-7392","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-\u6587\u5b57\u81ea\u9069\u61c9\u9ad8\u5ea6-\ud83d\udcdd\ud83d\udcbb_1675475190.8040378.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Ve","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7392","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=7392"}],"version-history":[{"count":0,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7392\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7391"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}