में सीमाओं से बाहर छवि दिखाएं, मुझे एक छवि और छवि के लिए नाम दिखाने के लिए एक अनुकूलित यूआईसीओलेक्शन व्यूसेल बनाना है, और छवि के शीर्ष पर, एक फ्रेम छवि है जो 2 पिक्सेल बड़ी है छवि की तुलना में चौड़ाई और ऊंचाई। हालांकि, कोई फर्क नहीं पड़ता कि मैं क्या करता हूं, छवि फ्रेम छवि से बड़ी प्रतीत होती है। मैंने तालिका दृश्य के लिए एक ही काम किया, और यह सही काम करता है।UIImageView एक UICollectionViewCell उप वर्ग
//GridCell.h
@interface GridCell : UICollectionViewCell
@property(nonatomic, strong) UILabel *lblName;
@property(nonatomic, strong) UIImageView *image;
@end
//GridCell.m
#import "GridCell.h"
@implementation GridCell
@synthesize image, lblName;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
UIImage *bg = [UIImage imageNamed:@"borderUIimgLg.png"];
UIImageView *bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, frame.size.width, frame.size.width)];
[bgImage setImage:bg];
[bgImage setContentMode:UIViewContentModeScaleAspectFill];
NSLog(@"BG Image size %f, %f", bgImage.frame.size.width, bgImage.frame.size.height);
UIImageView *contentImage = [[UIImageView alloc] initWithFrame:CGRectMake(2.0, 2.0, frame.size.width-4.0, frame.size.width-4.0)];
[contentImage setContentMode:UIViewContentModeScaleAspectFill];
[contentImage setClipsToBounds:YES];
self.image = contentImage;
[self.contentView addSubview:self.image];
[self.contentView addSubview:bgImage];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(2.0, frame.size.width, frame.size.width - 4.0, 21.0)];
[label setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:11.0]];
[label setTextAlignment:NSTextAlignmentCenter];
[label setBackgroundColor:[UIColor clearColor]];
self.lblName = label;
[self.contentView addSubview:self.lblName];
}
return self;
}
UICollectionViewCell तो कोड में, bgImage 67 x 67 होने के लिए हमेशा होना चाहिए तथा इसके मूल है, 67 x 100 का एक आकार की है (0,0:
यहाँ कोड है) और सामग्री छवि का फ्रेम होना चाहिए (0,0,63,63)। डिबगिंग करके, यह सही लगता है। हालांकि, bgImage से हमेशा conentimage बड़ा है। हालांकि छवि का मूल आकार 80 x 80 है। मैंने setClipToBounds, किसी भी कक्ष पर setContentViewMode को आजमाया है। सामग्री दृश्य या छवि दृश्य, लेकिन कोई भी काम नहीं करता है।
समस्या के बारे में एक स्क्रीनशॉट संलग्न है।
किसी भी मदद की सराहना की जाती है।
मैंने निब में और स्टोरीबोर्ड में सभी तत्वों को लेआउट करने का भी प्रयास किया, वही परिणाम प्राप्त करें। – Zhao