Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> iOS
iOS
  1. วิธีให้ UILabel มีความสูงแบบไดนามิก (Dynamic Height) ใน Swift

    ทำให้ UILabel ขยายความสูงตามเนื้อหา ใช้ Auto Layout + numberOfLines = 0 หลักการสำคัญ numberOfLines = 0 (Unlimited Lines) Constraints: Top, Leading, Trailing, Bottom (หรือ Height ≥) ไม่ตั้ง Height Constraint คงที่ Content Hugging/Compression Resistance Priority เหมาะสม โค้ดตัวอย่าง let label = U

  2. วิธีใช้ UICollectionView ใน Swift

    UICollectionView แสดงข้อมูลแบบ Grid/Custom Layout ใช้ DataSource, Delegate, FlowLayout Setup แบบโปรแกรม CGSize { let width = (collectionView.bounds.width - 30) / 2 // 2 columns return CGSize(width: width, height: width) } } Compositional Layout (iOS 13+ แนะนำ) UICollectionVi

  3. วิธีสร้าง UITextView ที่เลื่อนได้ (Scrollable) ใน iOS

    UITextView สืบทอดจาก UIScrollView เลื่อนได้อัตโนมัติเมื่อข้อความยาวกว่าพื้นที่ แต่อยู่ที่ต้องตั้งค่าให้ถูกต้อง Storyboard Setup ลาก Text View จาก Object Library Attributes Inspector → ติ๊ก Scrolling Enabled ✓ ติ๊ก User Interaction Enabled ✓ ตั้ง Constraints: Top, Leading, Trailing, Bottom (หรือ He

  4. วิธีโหลดและแสดงรูปภาพใน iOS App ด้วย Swift

    โหลดและแสดงรูปภาพใน iOS ใช้ UIImageView + UIImage 1. รูปภาพใน Asset Catalog (Local) ลากไฟล์รูป → Assets.xcassets → สร้าง New Image Set ใส่รูป 1x, 2x, 3x ให้ครบ ตั้งชื่อ เช่น profile_image // โหลดจาก Asset let image = UIImage(named: profile_image) imageView.image = image 2. โหลดจาก Bundle (Fil

  5. วิธาจัดการ Swipe Gesture ซ้าย/ขวา ใน iOS App

    ใช้ UISwipeGestureRecognizer จัดการ Swipe Gesture 4 ทิศทาง (Left, Right, Up, Down) วิธีที่ 1: Storyboard ลาก Swipe Gesture Recognizer จาก Object Library → วางบน View Controller Attributes Inspector → Swipe → เลือก Direction (Right/Left/Up/Down) Ctrl+Drag ไป Class → Action: @IBAction func swipeHand

  6. วิธีแสดงรูปภาพมุมโค้ง (Rounded Corners) ใน iOS App ด้วย Swift

    ใช้ layer.cornerRadius และ clipsToBounds = true ทำให้ UIImageView หรือ View ใดๆ มีมุมโค้ง วิธีพื้นฐาน let imageView = UIImageView(image: UIImage(named: photo)) imageView.frame = CGRect(x: 20, y: 50, width: 200, height: 200) imageView.contentMode = .scaleAspectFill // ทำมุมโค้ง imageView.layer.cor

  7. วิธีผสานรวม PayU Money ใน iOS ด้วย Swift

    PayU Money เป็น Payment Gateway ยอดนิยมในอินเดีย ผสานรวมผ่าน iOS SDK ขั้นตอนการผสานรวม 1. สมัครบัญชี PayU Money สมัครที่ payu.in ได้ Merchant Key, Salt, Merchant ID จาก Dashboard 2. ติดตั้ง SDK # Terminal git clone --recursive https://github.com/payu-intrepos/PayUMoney-IOS-SDK.git # หรือ Coco

  8. Push Segue จาก UITableViewCell ไป ViewController ใน Swift

    สร้าง Segue จาก Prototype Cell ใน Table View Controller ไป View Controller อื่น ขั้นตอนใน Storyboard ลบ View Controller เริ่มต้น → เพิ่ม Table View Controller และ View Controller เลือก Prototype Cell → Attributes Inspector → Identifier: cell Ctrl+Drag จาก Cell → View Controller ใหม่ → เลือก Show (

  9. ตรวจสอบว่าสตริงมีสตริงย่อยหรือไม่ใน Swift

    เช็คว่าสตริงหนึ่งมีสตริงอีกตัวหนึ่งอยู่ภายใน ใช้ contains(_:) หรือ range(of:) วิธีที่ 1: contains(_:) - เรียบง่ายที่สุด (Swift 2+) let fullString = Tutorials Point let substring = Point if fullString.contains(substring) { print(Contains Point) } else { print(Does not contain) } // Output:

  10. สามารถเปลี่ยนขนาด UIActivityIndicatorView ใน Swift ได้หรือไม่

    สามารถเปลี่ยนขนาดได้ด้วย CGAffineTransform แต่ ไม่แนะนำ เพราะภาพจะเบลอ (Blurry) และไม่ใช่การ Scale ที่เหมาะสม วิธีที่พบบ่อย (ไม่แนะนำ) let indicator = UIActivityIndicatorView(style: .large) indicator.color = .red // Scale 2.5 เท่า let transform = CGAffineTransform(scaleX: 2.5, y: 2.5) indicator.t

  11. วิธีใช้ MBProgressHUD กับ Swift

    MBProgressHUD เป็น Library แสดง Loading Indicator (HUD) ยอดนิยม ติดตั้งผ่าน CocoaPods ติดตั้ง (CocoaPods) 1.2.0 # Terminal pod install การใช้งานพื้นฐาน import MBProgressHUD // แสดง HUD let hud = MBProgressHUD.showAdded(to: self.view, animated: true) hud.label.text = Loading... hud.detailsLabe

  12. วิธีดึงตัวอักษร 4 ตัวสุดท้ายจาก String ใน Swift

    ใช้ suffix(_:) (Swift 4+) หรือ substring (เก่า) เพื่อดึงตัวอักษรท้ายสตริง วิธีที่ 1: suffix(_:) - แนะนำ (Swift 4+) let str = 12312$$33@ let last4 = str.suffix(4) print(last4) // 33@ (Substring) // แปลงเป็น String let last4String = String(str.suffix(4)) print(last4String) // 33@ วิธีที่ 2: subst

  13. วิธีเปรียบเทียบ NSDate (Date) 2 ตัวใน iOS/Swift

    เปรียบเทียบ Date 2 ตัวใน Swift ใช้เมธอด compare(_:) คืนค่า ComparisonResult สร้าง Date เพื่อทดสอบ let calendar = Calendar.current var components1 = DateComponents(year: 1993, month: 6, day: 5) var components2 = DateComponents(year: 1995, month: 2, day: 4) let date1 = calendar.date(from: component

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