2010-08-09 12 views
5

मेरे पास UITableViewCell में UITextField है। किसी कारण से स्पष्ट बटन टेक्स्ट फ़ील्ड के पाठ पर संरेखित नहीं है।UITextField में टेक्स्ट के साथ स्पष्ट बटन क्यों गठबंधन नहीं किया गया है?


cell.selectionStyle = UITableViewCellSelectionStyleNone; 
usernameField = [[UITextField alloc] initWithFrame:CGRectMake(22, 10, cell.contentView.frame.size.width, cell.contentView.frame.size.height)]; 
usernameField.adjustsFontSizeToFitWidth = YES; 
usernameField.placeholder = @"Username"; 
usernameField.backgroundColor = [UIColor clearColor]; 
usernameField.keyboardType = UIKeyboardTypeDefault; 
usernameField.autocapitalizationType = UITextAutocorrectionTypeNo; 
usernameField.autocorrectionType = UITextAutocorrectionTypeNo; 
usernameField.returnKeyType = UIReturnKeyNext; 
usernameField.delegate = self; 
usernameField.clearButtonMode = UITextFieldViewModeAlways; 
[usernameField setEnabled:YES]; 
[cell addSubview:usernameField]; 
[usernameField becomeFirstResponder]; 
[usernameField release]; 

यहाँ चित्र समस्या प्रदर्शित करने के लिए है और:: यहाँ मेरी textfield कोड है Screenshot

संपादित करें: मैं भी - (CGRect)clearButtonRectForBounds:(CGRect)bounds साथ की कोशिश की और अभी भी कुछ नहीं

उत्तर

19

अपने contentVerticalAlignment संपत्ति क्या है? मैंने यह समस्या तब दिखाई है जब स्पष्ट बटन केंद्र गठबंधन होता है लेकिन टेक्स्ट शीर्ष पर गठबंधन होता है। निम्नलिखित में अपना टेक्स्टफील्ड संरेखण सेट करने का प्रयास करें:

usernameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 

इसके साथ कोई भाग्य?

+0

आप मदद करने के लिए बहुत-बहुत धन्यवाद, लेकिन अब पाठ और स्पष्ट बटन सेल की तह तक गठबंधन कर रहे हैं। मैं यह कोड वास्तव में पाठ को संरेखित करता हूं, स्पष्ट बटन नहीं। मैं सेल के केंद्र में स्पष्ट बटन को संरेखित करना चाहता हूं कोई सुझाव? –

+0

यह काम किया! मैंने स्पष्ट बटन –

+0

धन्यवाद के लिए फिट करने के लिए सीजीआरएक्ट विशेषताओं को बदल दिया है। स्पष्ट करने के लिए, मैंने ऊर्ध्वाधर ऑफसेट को सही करने के लिए सेल और टेक्स्ट फ़ील्ड की ऊंचाई को ध्यान में रखा। CGRect newFrame = albumTitleTextField.frame; newFrame.origin.y = (cell.bounds.size.height - newFrame.size.height)/2.0; [एल्बम टिटलेटेक्स्टफिल्ड सेटफ्रेम: नया फ्रेम]; –

संबंधित मुद्दे