UIColor Macros

Objective-C 28 ม.ค. 2013

ในการเขียน code Objective-C การกำหนดค่าสี นั้นค่อนข่างยุ่งยาก เราสามารถทำให้ง่ายขึ้นได้โดย

#define RGB(r, g, b)
[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#define RGBA(r, g, b, a)
[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

การนำไปใช้

// Code with macro
msgLabel.textColor = RGB(255, 251, 204);

แท็ก

Onyx

Just a middle-aged programmer, Can do many things but not the most.