2010-07-16 72 views
44

Có cách nào để căn chỉnh văn bản theo chiều dọc trong một số UITextField nửa đường giữa UIControlContentVerticalAlignmentCenterUIControlContentVerticalAlignmentBottom hoặc tôi có phải đi với một trong số đó không?UITextField Căn chỉnh theo chiều dọc

+0

có thể trùng lặp của http://stackoverflow.com/questions/2694411/text-inset-for-uitextfield – titaniumdecoy

+1

@titaniumdecoy Nó không phải. –

Trả lời

4

Bạn nên phân lớp một UITextField, và ghi đè lên các phương pháp sau đây:

- (CGRect) textRectForBounds: (CGRect) bounds 
{ 
    CGRect origValue = [super textRectForBounds: bounds]; 

    /* Just a sample offset */ 
    return CGRectOffset(origValue, 0.0f, 4.0f); 
} 

- (CGRect) editingRectForBounds: (CGRect) bounds 
{ 
    CGRect origValue = [super textRectForBounds: bounds]; 

    /* Just a sample offset */  
    return CGRectOffset(origValue, 0.0f, 4.0f); 
} 
Các vấn đề liên quan