Add navigationBar with + button

ใส่ชื่อแอป เพิ่มปุ่มบวก

เรามาเพิ่มให้มี แถบด้านบนกันดีกว่า จะได้เตรียมไว้ทำหน้าเพิ่ม todo item ด้วย แบบนี้

ขั้นแรกให้เราเลือกที่ ViewController ใน document outline ก่อน จากนั้นกดที่เมนู Editor -> Embed In -> Navigation Controller

เราจะได้ Navigation Controller มาหนึ่งอัน ชี้มาที่ ViewController

จากนั้นให้เราตั้งชื่อ โดยการเลือกที่ Navigation Item ของ ViewController ที่เพิ่มมา เลือก Attributes Inspector ใส่ Todo ลงใน Title property

เพิ่มปุ่ม Add โดยการลาก Bar Button Item จาก Object Library ไปที่มุมขวาของ Navigation Bar

เลือก System Item เป็น Add ปุ่มจะเปลี่ยนเป็นเครื่องหมาย +

เมื่อรันแอปอีกครั้งจะได้หน้าตาแบบนี้

Last updated