2012年6月19日 星期二

UITextField Set Content Alignment

UITextField 文字對齊的方式除了
[textField setTextAlignment:UITextAlignmentLeft];
[textField setTextAlignment:UITextAlignmentCenter];
[textField setTextAlignment:UITextAlignmentRight];
之外,還可以針對內容做水平或垂直對齊。

垂直
typedef enum {
UIControlContentVerticalAlignmentCenter  = 0,
UIControlContentVerticalAlignmentTop     = 1,
UIControlContentVerticalAlignmentBottom  = 2,
UIControlContentVerticalAlignmentFill    = 3,
} UIControlContentVerticalAlignment;
水平
typedef enum {
UIControlContentHorizontalAlignmentCenter = 0,
UIControlContentHorizontalAlignmentLeft   = 1,
UIControlContentHorizontalAlignmentRight  = 2,
UIControlContentHorizontalAlignmentFill   = 3,
} UIControlContentHorizontalAlignment;
使用方式如下:
//垂直
[textField setContentVerticalAlignment:UIControlContentVerticalAlignmentBottom];
//水平
[textField setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];

沒有留言:

張貼留言