Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> iOS
iOS
  1. ความแตกต่างระหว่าง UITableViewController และ UIViewController

    UIViewController และ UITableViewController ต่างกันที่หน้าที่และ Protocol ที่ Conform UIViewController Base Class สำหรับจัดการ View หนึ่งหน้าจอ Life Cycle: viewDidLoad, viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear ใช้เมื่อหน้าจอมีหลาย Component (ไม่ใช่แค่ Table) ต้อง Conform U

  2. วิธีตั้งค่าพื้นหลัง Navigation Bar ใน iOS

    ตั้งค่าสีพื้นหลัง Navigation Bar ได้ 2 วิธี: Storyboard และโค้ด (รองรับ iOS 13+ Appearance API) วิธีที่ 1: Storyboard (Xcode 13+) Select Navigation Bar ใน Document Outline Attributes Inspector → Appearance → Configure Standard, Scroll Edge, Compact ตั้งค่า Background Color, Title Color, Tint Color

  3. วิธีสร้าง WebView ใน iOS/iPhone

    ใช้ WKWebView (WebKit Framework) แทน UIWebView ที่ Deprecated แล้ว Setup Import WebKit Storyboard: ลาก WKWebView จาก Object Library เชื่อม IBOutlet: @IBOutlet weak var webView: WKWebView! โหลดเว็บไซต์ override func viewDidLoad() { super.viewDidLoad() guard let url = URL(string: htt

  4. วิธีเพิ่ม Cell ใหม่เข้า UITableView ใน Swift

    เพิ่ม Cell ใหม่ใน UITableView ใช้ insertRows(at:with:) พร้อมอัปเดต Data Source ขั้นตอนพื้นฐาน อัปเดต Data Array (เพิ่มข้อมูล) เรียก tableView.insertRows(at: [indexPath], with: .automatic) โค้ดตัวอย่าง UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: Cell, for:

  5. วิธีส่งอีเมลพร้อมไฟล์แนบ (Attachment) ใน Swift

    ใช้ MFMailComposeViewController (MessageUI Framework) ส่งอีเมลพร้อม Attachment Setup Project Settings → Signing & Capabilities → + Capability → Mail (ถ้าจำเป็น) Import MessageUI Conform MFMailComposeViewControllerDelegate โค้ดส่งอีเมลพร้อมไฟล์ PDF import MessageUI class ViewController: UIViewC

  6. พัฒนา/ย้ายแอปสำหรับความละเอียดหน้าจอ iPhone 5

    iPhone 5 (2012) มีความละเอียด 640×1136 (Aspect Ratio 16:9) ต่างจาก iPhone 4/4S (3:2) ปัจจุบัน Xcode ใช้ Auto Layout และ Size Classes จัดการทุกขนาดได้อัตโนมัติ บริบททางประวัติศาสตร์ iPhone 4/4S: 640×960 (3:2) iPhone 5/5s/SE(1st): 640×1136 (16:9) - First 4-inch iPhone 6/7/8: 750×1334 (4.7) iPhone 6+

  7. วิธีใช้ Swift รันใน Background เพื่อดึงตำแหน่งที่ตั้งปัจจุบัน

    รับ Location ใน Background ต้องตั้งค่า Capabilities, Info.plist, และ CLLocationManager ให้ถูกต้อง 1. Capabilities (Xcode Project Settings) Signing & Capabilities → + Capability → Background Modes ติ๊ก Location updates 2. Info.plist Keys <key>NSLocationAlwaysAndWhenInUseUsageDescription<

  8. วิธีเรียก RESTful API ใน iOS/iPhone ด้วย Swift

    ใช้ URLSession (Native) สำหรับ Network Request ไม่ต้องใช้ Library ภายนอก โครงสร้างพื้นฐาน import Foundation struct APIService { static let shared = APIService() private let session = URLSession.shared func request(_ endpoint: Endpoint, completion: @escaping (Result Void) {

  9. ถ่ายภาพจากกล้อง iOS ด้วย Swift

    ใช้ UIImagePickerController (ง่าย) แทน AVFoundation (ซับซ้อน) สำหรับถ่ายภาพและแสดงผล ขั้นตอนการทำ เพิ่ม UIImageView ใน Storyboard → เชื่อม IBOutlet Conform Protocol: UIImagePickerControllerDelegate, UINavigationControllerDelegate เพิ่ม Tap Gesture หรือ Button เรียกกล้อง Implement Delegate Method

  10. วิธีเปลี่ยนสีพื้นหลังปุ่ม (Button Background Color) ใน Swift

    เปลี่ยนสีพื้นหลัง UIButton ได้ 2 วิธี: Storyboard และโค้ด วิธีที่ 1: Storyboard เลือก UIButton ใน Storyboard Attributes Inspector → Background → เลือกสี หรือใช้ Tint Color สำหรับ System Button วิธีที่ 2: โค้ด (Programmatically) // UIButton Configuration (iOS 15+ แนะนำ) var config = UIButton.Con

  11. ขนาดและ Radius ที่แน่นอนของ iPhone App Icons

    ทุก iOS App ต้องมี App Icon หลายขนาด สำหรับ Home Screen, Spotlight, Settings, Notification, App Store กฎทั่วไป Format: PNG (ไม่รองรับ JPEG) ไม่มี Transparency (Alpha channel = 100%) Square ไม่มี Round Corners (ระบบจะทำมุมโค้งให้อัตโนมัติ) App Store Icon: 1024×1024 px (จำเป็น) ขนาด Icon ทั้งหมด (

  12. วิธาสร้างปุ่ม Back Arrow บน Toolbar ใน iPhone/iPad

    สร้างปุ่มลูกศรย้อนกลับบน Toolbar ใช้ UIBarButtonItem และรูปภาพลูกศร ขั้นตอนใน Storyboard ลาก Toolbar จาก Object Library วางด้านล่าง View Controller Toolbar จะมี Bar Button Item มาให้ 1 ตัว ตั้ง Constraint: Bottom, Leading, Trailing = 0, Height = 44 เลือก Bar Button Item → Attributes Inspector ใน I

  13. วิธีตรวจสอบ iOS Version ที่รันอยู่บนอุปกรณ์

    ใช้ UIDevice.current.systemVersion เพื่อดึง iOS Version เป็น String โค้ดพื้นฐาน print(iOS Version: \(UIDevice.current.systemVersion)) // Output: iOS Version: 17.2.1 แปลงเป็น Version Object เพื่อเปรียบเทียบ = 15.0 { print(iOS 15+ features available) } ใช้ OperatingSystemVersion (แนะนำ) let

  14. วิธีเปลี่ยนสีและความหนาขอบ (Border) ของ UIView ใน Cocoa Touch

    เปลี่ยน Border Color และ Border Width ของ UIView ได้ 2 วิธี วิธีที่ 1: โค้ดโดยตรง let view = UIView() view.layer.borderWidth = 2.0 view.layer.borderColor = UIColor.systemBlue.cgColor view.layer.cornerRadius = 8 // เพิ่มมุมโค้งได้ด้วย วิธีที่ 2: IBDesignable + IBInspectable (แก้ไขใน Storyboard)

  15. วิธีเพิ่มรูปภาพใน iOS Simulator สำหรับการทดสอบ

    เมื่อต้องทดสอบฟีเจอร์อัปโหลด/เลือกรูปภาพ แต่ไม่มีอุปกรณ์จริง สามารถเพิ่มรูปใน Simulator ได้หลายวิธี วิธีที่ 1: Drag & Drop (ง่ายที่สุด) เปิด Simulator ลากไฟล์รูปจาก Finder → วางบนหน้าจอ Simulator รูปจะปรากฏใน Photos App ทันที วิธีที่ 2: ใช้ Safari ใน Simulator เปิด Safari ใน Simulator ค้นหารูปภ

  16. ภาพหน้าจอ (Screenshot) ของ iOS Simulator เก็บอยู่ที่ไหน

    ตำแหน่งเก็บ Screenshot ของ Simulator ขึ้นอยู่กับวิธีการถ่าย New Screenshot ตำแหน่ง: Desktop ชื่อไฟล์: Simulator Screen Shot - iPhone 15 Pro - 2024-01-15 at 14.30.22.png รูปแบบ: Simulator Screen Shot - {Device} - {YYYY-MM-DD at HH.MM.SS}.png 2. Command + Shift + 3 / 4 (macOS Screenshot) ตำแหน่ง: D

  17. วิธีส่งอีเมลจากแอป iPhone

    ไม่สามารถส่งอีเมลโดยตรงจากแอปได้ (เว้นแต่เป็น Mail App) แต่สามารถเปิด Mail App พร้อมข้อมูล Pre-filled หรือใช้ MFMailComposeViewController วิธีที่ 1: URL Scheme (mailto:) - เรียบง่าย func sendEmail(to email: String, subject: String? = nil, body: String? = nil) { var urlComponents = URLComponents

Total 190 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:8/10  20-คอมพิวเตอร์/Page Goto:1 2 3 4 5 6 7 8 9 10