2010-05-04 4 views
5

में UIAlertView की चौड़ाई बदलें आईफोन या आईपैड में UIAlertView के फ्रेम को बदलने का कोई तरीका है। मैंने निम्नलिखित प्रतिनिधि विधि - (void)willPresentAlertView:(UIAlertView *)alertView;आईपैड

में फ्रेम बदलने की कोशिश की लेकिन फिर भी अलर्टव्यू की चौड़ाई अपरिवर्तित बनी रही। और मुझे लगता है कि आईपैड में एक छोटा अलर्टव्यू समझ में नहीं आता है। और मुझे लगता है कि कम से कम आईपैड में इसे हासिल करने का एक तरीका होना चाहिए।

धन्यवाद, कृष्णन।

+0

क्या तुमने कभी यह करने के लिए एक तरह से मिला? बस उत्सुक, यहां बहुत सारे जवाब, तीन साल बीत गए ... आदि – Morkrom

उत्तर

8

हम्म, इस कोड को ठीक काम करता है (, को छोड़कर जब आप आकार को कम करने की कोशिश कर रहे हैं - इस मामले में कारण आप कुछ बुरा प्रतिपादन प्राप्त कर सकते हैं):

- (void)willPresentAlertView:(UIAlertView *)alertView { 
    alertView.frame = CGRectMake(x, y, width, height); 
} 

हो सकता है, आप UIAlertView के प्रतिनिधि सेट करने के लिए भूल गया someAlertView.delegate = self;

 

अद्यतन   ↓

की तरह कुछ के साथ

codepart:

- (IBAction)go:(id)sender { 
    UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:nil 
     otherButtonTitles:nil] autorelease]; 
    alert.delegate = self; 
    [alert show]; 
} 

- (void)willPresentAlertView:(UIAlertView *)alertView { 
    alertView.frame = CGRectMake(5.f, 1.f, 100.f, 200.f); 
} 

परिणाम (मेरे आइपॉड पर): जब मैं फ्रेम सेट या दृश्य की पृष्ठभूमि फ्रेम को बदलने का उपयोग डिवाइस में बुरी तरह से प्रस्तुत किया गया है http://dl.dropbox.com/u/6455784/alert_view_frame.png

+1

मैंने प्रतिनिधि को सेट किया था। अलर्टव्यू की ऊंचाई बदल गई लेकिन चौड़ाई नहीं। क्या यह वास्तव में आपके लिए काम करता है? – Krishnan

+0

हां। लेकिन, जब दृश्य की चौड़ाई कम पाठ प्रदर्शित करने (प्रतिपादन) के लिए आवश्यक थी, तो दृश्य का पृष्ठभूमि फ्रेम बुरी तरह से प्रस्तुत किया गया था (फ्रेम आयताकार का बायां हिस्सा गोलाकार था, लेकिन सही नहीं था)। – kpower

+0

क्या आप अपने समाधान कार्यों की पुष्टि कर सकते हैं? Astalapista कहते हैं कि यह काम नहीं कर रहा है। – Krishnan

3

नहीं textfields, मेरे alertview पर मौजूद हैं अभी भी । यह चीज केवल सिम्युलेटर में ठीक काम करेगी।

3

मुझे पता है कि यह एक पुराना सवाल है लेकिन मुझे एक ही समस्या का सामना करना पड़ रहा था और यहां दिए गए उत्तरों ने मेरी मदद की। आईपैड पर अधिक टेक्स्ट समायोजित करने के लिए मुझे शीर्षक और संदेश टेक्स्ट फ़ील्ड बढ़ाने की आवश्यकता थी।

मैंने जो किया वह 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 
           ); 
} 

अगर यह ऐसा करने का सबसे अच्छा तरीका है, लेकिन यह मेरे लिए काम किया मुझे नहीं पता।

+0

हाँ यह आईओएस 7 से पहले काम कर रहा था, लेकिन आईओएस 7 के लिए यह काम नहीं कर रहा है। – UserDev

4

यह वह समाधान है जो आप ढूंढ रहे हैं यदि आप मानक UIAlertView की चौड़ाई को बड़े टेक्स्ट फ़ील्ड और एक ठीक बटन के साथ बदलना चाहते हैं। मेरे मामले में मैं बस बड़ी मात्रा में पाठ के साथ एक चेतावनी चाहता था। और उस पाठ को टेक्स्टव्यू स्क्रॉल किए बिना सभी दृश्यमान हैं। चाल यह है कि आपको अंदर/कुछ विचारों की चौड़ाई बदलनी है। कोई गारंटी नहीं है कि यह ऐप अनुमोदन पास करेगी। उन्हें UIAlertTextView मिल सकता है और इसे अस्वीकार कर सकता है।

#define ALERT_VIEW_WIDTH 600 
#define ALERT_PADDING 20 
-(void) willPresentAlertView:(UIAlertView*) alertView 
{ 
    id thing; 
    int center=alertView.center.x-ALERT_VIEW_WIDTH/2; 
    for (thing in alertView.subviews) 
    { 
     NSLog(@"%@", [[thing class] description]); 
     if([[[thing class] description] isEqualToString:@"UIAlertTextView"]) 
     { 
      UIView* v=(UIView*)thing; 
      v.frame=CGRectMake(v.frame.origin.x+ALERT_PADDING, v.frame.origin.y, ALERT_VIEW_WIDTH-ALERT_PADDING*3, 250); 
     } 
     if([[[thing class] description] isEqualToString:@"UIThreePartButton"]) 
     { 
      UIView* v=(UIView*)thing; 
      v.frame=CGRectMake(v.frame.origin.x+ALERT_PADDING, v.frame.origin.y, ALERT_VIEW_WIDTH-ALERT_PADDING*3, v.frame.size.height); 
     } 
    } 
    alertView.frame=CGRectMake(center, alertView.frame.origin.y, ALERT_VIEW_WIDTH, 360); 

} 
+0

क्या आपको ऐप स्वीकृत किया गया था जिसमें आपने इसका इस्तेमाल किया था? –

0

उपयोग संबंधित ऊंचाई iPhone और iPad के लिए क्रमशः चौड़ाई के साथ इस विधि:

- (void)willPresentAlertView:(UIAlertView *)alertView { 
    [alertView setFrame:CGRectMake(5, 20, 300, 420)]; 
}