मुझे पता है कि यह एक पुराना सवाल है लेकिन मुझे एक ही समस्या का सामना करना पड़ रहा था और यहां दिए गए उत्तरों ने मेरी मदद की। आईपैड पर अधिक टेक्स्ट समायोजित करने के लिए मुझे शीर्षक और संदेश टेक्स्ट फ़ील्ड बढ़ाने की आवश्यकता थी।
मैंने जो किया वह UIAlertView willPresentAlertView: प्रतिनिधि विधि और शीर्षक और संदेश के रूप में कार्य करने के लिए दो UILabel ऑब्जेक्ट्स को लागू करता है। मैं इन दो लेबलों के फ्रेम आकार और उत्पत्ति को कॉन्फ़िगर करने में सक्षम था। टेक्स्ट फ़ील्ड के वांछित आकार प्राप्त करने के बाद मैं नए टेक्स्ट को समायोजित करने के लिए अलर्टव्यू का आकार बदलता हूं। फिर मैं बटन ढूंढने और उसके फ्रेम को समायोजित करने के लिए अलर्टव्यू के सबव्यूज़ के माध्यम से पुन: प्रयास करता हूं।
- (void)willPresentAlertView:(UIAlertView *)alertView {
// add a new label and configure it to replace the title
UILabel *tempTitle = [[UILabel alloc] initWithFrame:CGRectMake(10,20,350, 20)];
tempTitle.backgroundColor = [UIColor clearColor];
tempTitle.textColor = [UIColor whiteColor];
tempTitle.textAlignment = UITextAlignmentCenter;
tempTitle.numberOfLines = 1;
tempTitle.font = [UIFont boldSystemFontOfSize:18];
tempTitle.text = alertView.title;
alertView.title = @"";
[alertView addSubview:tempTitle];
[tempTitle release];
// add another label to use as message
UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, 350, 200)];
tempLabel.backgroundColor = [UIColor clearColor];
tempLabel.textColor = [UIColor whiteColor];
tempLabel.textAlignment = UITextAlignmentCenter;
tempLabel.numberOfLines = 20;
tempLabel.text = alertView.message;
[alertView addSubview:tempLabel];
// method used to resize the height of a label depending on the text height
[self setUILabel:tempLabel withMaxFrame:CGRectMake(10,50, 350, 300) withText:alertView.message];
alertView.message = @"";
// set the frame of the alert view and center it
alertView.frame = CGRectMake(CGRectGetMinX(alertView.frame) - (370 - CGRectGetWidth(alertView.frame))/2 ,
alertView.frame.origin.y,
370,
tempLabel.frame.size.height + 120);
// iterate through the subviews in order to find the button and resize it
for(UIView *view in alertView.subviews)
{
if([[view class] isSubclassOfClass:[UIControl class]])
{
view.frame = CGRectMake (view.frame.origin.x+2,
tempLabel.frame.origin.y + tempLabel.frame.size.height + 10,
370 - view.frame.origin.x *2-4,
view.frame.size.height);
}
}
[tempLabel release];
}
और विधि लेबल का आकार बदलने के लिए इस्तेमाल किया:
- (void)setUILabel:(UILabel *)myLabel withMaxFrame:(CGRect)maxFrame withText:(NSString *)theText{
CGSize stringSize = [theText sizeWithFont:myLabel.font constrainedToSize:maxFrame.size lineBreakMode:myLabel.lineBreakMode];
myLabel.frame = CGRectMake(myLabel.frame.origin.x,
myLabel.frame.origin.y,
myLabel.frame.size.width,
stringSize.height
);
}
अगर यह ऐसा करने का सबसे अच्छा तरीका है, लेकिन यह मेरे लिए काम किया मुझे नहीं पता।
क्या तुमने कभी यह करने के लिए एक तरह से मिला? बस उत्सुक, यहां बहुत सारे जवाब, तीन साल बीत गए ... आदि – Morkrom