2011-03-22 44 views

回答

3

而不是使用titleForRow你的選擇器視圖的代表方法,你應該使用viewForRow - 這樣你可以返回一個使用右對齊文本的UILabel。如果您只使用titleForRow方法,則您無法控制文本的顯示方式,但如果您使用後者,則可以根據您的內容進行自定義。

+0

thaaaaaaaaaaaaaaaankx這麼多IGOT it.Really我感謝你的幫助。 – DAVEd 2011-03-26 01:53:31

2

@lxt答案是正確的,但如果他/她原諒我,我會把完整的代碼

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ 
    UILabel *lblPickerTitle = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 280, 30)] autorelease]; 
    lblPickerTitle.text = [pickerArray objectAtIndex:row]; 
    lblPickerTitle.font = [UIFont fontWithName:@"Arial" size:20]; 
    lblPickerTitle.textAlignment = UITextAlignmentRight; 
    return lblPickerTitle; 
}