2010-04-13 16 views

उत्तर

9

इंटरफ़ेस निर्माता खिंचाव वाली छवियों का समर्थन नहीं करता है।

-(void) viewDidLoad { 
    [super viewDidLoad]; 
    [myImageView setImage:[[myImageView image] stretchableImageWithLeftCapWidth:5 topCapHeight:5 ]]; 
} 
+0

'इंटरफ़ेस बिल्डर खींचे images.' ==> क्षमा का समर्थन नहीं करता अनुमति देते हैं, लेकिन यह कर देता है। 'स्ट्रैचिंग' भाग इस भूमिका को लेता है, नीचे दिए गए उत्तर में – samthui7

2

यह वर्तमान में (संस्करण 4.5 के रूप में) इंटरफेसबिल्डर की एक सीमा है। हालांकि, प्रत्येक बटन के लिए IBOutlet बनाने और मैन्युअल रूप से निर्दिष्ट करने के लिए कि छवि viewDidLoad में फैला हुआ है, यह एक अच्छा समाधान नहीं है, अगर इससे अन्य कारणों से यूआई को अधिक बोझिल और अधिक भंगुर बनाने में मदद मिलती है।

इसके बजाए, UIButton सबक्लास बनाएं जो हमेशा डिफ़ॉल्ट रूप से किसी भी पृष्ठभूमि छवि को फैलाएगा। इस उदाहरण में मैं केवल सामान्य और हाइलाइट की गई पृष्ठभूमि छवि को खींचता हूं। उत्पादन-तैयार वर्ग के लिए आप शायद सभी पृष्ठभूमि और अग्रभूमि छवियों दोनों के राज्यों को जांचना चाहते हैं और उन्हें खींचें।

@implementation NTSTButton 

- (id) initWithCoder:(NSCoder *)aDecoder { 

    self = [super initWithCoder:aDecoder]; 
    if (self) { 
     /* There is no support in IB for stretchable images. So, let's 
      make sure _any_ background image assigned to this button 
      stretches correctly. 
      Note: Setting the stretch cap to 10px, which should work with 
      almost all button background images. 
     */ 
     UIImage *normalImage = 
       [[self backgroundImageForState:UIControlStateNormal] 
         stretchableImageWithLeftCapWidth:10 topCapHeight:10] ; 

     UIImage *highlightedImage = 
       [[self backgroundImageForState:UIControlStateHighlighted] 
         stretchableImageWithLeftCapWidth:10 topCapHeight:10] ; 

     [self setBackgroundImage:normalImage 
       forState:UIControlStateNormal]; 

     [self setBackgroundImage:highlightedImage 
       forState:UIControlStateHighlighted]; 
    } 
    return self; 
} 

@end 
+0

+1 दिशा के लिए धन्यवाद – Brenden

0

@answerbot की तरह, लेकिन 5.0+ iOS के लिए अद्यतन stretchableImageWithLeftCapWidth:topCapHeight: के रूप में अब मान्य नहीं है।

@implementation UIButtonStretchable 

- (id) initWithCoder:(NSCoder *)aDecoder { 
    self = [super initWithCoder:aDecoder]; 
    if (self) { 
     [self setBackgroundImage: [[self backgroundImageForState:UIControlStateNormal] resizableImageWithCapInsets:UIEdgeInsetsMake(22,6,22,6)]forState:UIControlStateNormal]; 
     [self setBackgroundImage: [[self backgroundImageForState:backgroundImageForState:UIControlStateHighlighted] resizableImageWithCapInsets:UIEdgeInsetsMake(22,6,22,6)]forState:backgroundImageForState:UIControlStateHighlighted]; 
    } 
    return self; 
} 
@end 
0

iOS7 भी पेश एसेट कैटलॉग जहां आप अपने चित्रों के खींचे क्षेत्र निर्दिष्ट कर सकते हैं, लेकिन यह केवल काम करता है अगर आप केवल iOS7 समर्थन (यानी, आप मूल iPad, आइपॉड टच के उपयोगकर्ताओं के बारे में परवाह नहीं करते हैं, या 3 जीएस; हाँ, आईओएस में कोई विखंडन नहीं है)।

View धारा में https://developer.apple.com/library/ios/recipes/xcode_help-image_catalog-1.0/SlicinganImage/SlicinganImage.html#//apple_ref/doc/uid/TP40013303-CH4-SW1

0

उपयोग Stretching कॉन्फ़िगरेशन देखें।

  • सबसे पहले, व्यू मोड को Aspect fill पर बदलें।

  • फिर Stretching भाग में एक्स, वाई, चौड़ाई, ऊंचाई फ़ील्ड संपादित करें। उदाहरण के लिए: माना कि आप एक छवि का आकार 10x20 है, और ==> एक दृश्य के आकार 5x10 में फिट करना चाहते हैं एक्स = 5/10 = 0.5, वाई = 10/20 = 0,5

नोट: आईबी doesnot आप बड़ा फ्रेम में छोटी छवि के लिए "खिंचाव" का उपयोग करने, ताकि आप संभव के रूप में बड़े रूप में अपनी छवि को डिजाइन करने के लिए की जरूरत है

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