下面爲應用宏定義使用字體的一個具體實例:
對應用中需要用到的字體進行宏定義。
1
2
3
4
5
6
7
8
9
|
//
For text, messages, etc #define
DEFAULT_FONTSIZE 15 #define
DEFAULT_FONT(s) [UIFont fontWithName:@"ArialMT" size:s] #define
DEFAULT_BOLDFONT(s) [UIFont fontWithName:@"Arial-BoldMT" size:s] //
For table cells #define
CELL_FONTSIZE 16 #define
CELL_FONT(s) [UIFont fontWithName:@"Helvetica-Oblique" size:s] #define
CELL_BOLDFONT(s) [UIFont fontWithName:@"Helvetica-BoldOblique" size:s] |
在需要用到字體設置的代碼,使用上述宏來代替。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
//
Assume textFieldUserName is a UITextField [textFieldUserName
setFont:DEFAULT_FONT(DEFAULT_FONTSIZE)]; //
For bold and larger text [someTextField
setFont:DEFAULT_BOLDFONT(DEFAULT_FONTSIZE + 2)]; ... //
Set cell font sizes //
Assume cell is a UITableViewCell [[cell
textLabel] setFont:CELL_FONT(CELL_FONTSIZE)]; //
For bold and larger text [[cell
textLabel] setFont:CELL_BOLDFONT(CELL_FONTSIZE + 2)]; |