मुझे UIImageView के साथ वास्तव में अजीब समस्या है। मेरे पास एक छवि (एक आरजीबी पीएनजी) 45x45 पिक्सेल है जो मैं दृश्य में जोड़ता हूं। मैं देख सकता हूं कि दृश्य में जोड़े जाने के बाद छवि धुंधली हो गई है। यहाँ सिम्युलेटर (बाएं) में एक ही छवि है और Xcode में (दाएं):मेरा UIImageView क्यों धुंधला हुआ है?
- (id) initWithImage:(UIImage*) image {
self = [super initWithImage:image];
self.frame = CGRectMake(0, 0, 45, 45);
self.contentMode = UIViewContentModeScaleAspectFit;
self.quantity = 1;
if (self) {
self.label = [[UITextField alloc]initWithFrame:CGRectMake(0,40,45,25)];
self.label.font = [UIFont systemFontOfSize:16];
self.label.borderStyle = UITextBorderStyleNone;
self.label.enabled = TRUE;
self.label.userInteractionEnabled = TRUE;
self.label.delegate = self;
self.label.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
self.label.textAlignment = UITextAlignmentCenter;
}
self.userInteractionEnabled = TRUE;
// Prepare 3 buttons: count up, count down, and delete
self.deleteButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.deleteButton.hidden = NO;
self.deleteButton.userInteractionEnabled = YES;
self.deleteButton.titleLabel.font = [UIFont systemFontOfSize:20];
self.deleteButton.titleLabel.textColor = [UIColor redColor];
[self.deleteButton setTitle:@"X" forState:UIControlStateNormal];
[self.deleteButton addTarget:self action:@selector(deleteIcon:) forControlEvents:UIControlEventTouchUpInside];
self.upCountButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.upCountButton.hidden = NO;
self.upCountButton.userInteractionEnabled = YES;
[self.upCountButton setTitle:@"+" forState:UIControlStateNormal];
[self.upCountButton addTarget:self action:@selector(addQuantity:) forControlEvents:UIControlEventTouchUpInside];
self.downCountButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.downCountButton.hidden = YES;
self.downCountButton.userInteractionEnabled = YES;
[self.downCountButton setTitle:@"-" forState:UIControlStateNormal];
[self.downCountButton addTarget:self action:@selector(removeQuantity:) forControlEvents:UIControlEventTouchUpInside];
return self;
}
मैं इस तरह इसे बनाने:
alt text http://partywithvika.com/iconinsim.pngalt text http://partywithvika.com/iconinxcode.png
मैं इस initWithImage कोड के साथ कस्टम UIImageView वर्ग है :
UIImage *desertIcon = [UIImage imageNamed:@"desert.png"];
IconObj *desertIconView = [[IconObj alloc] initWithImage:desertIcon];
desertIconView.center = CGPointMake(265,VERTICAL_POINT_ICON);
desertIconView.type = [IconObj TYPE_DESERT];
[self.view addSubview:desertIconView];
[desertIconView release];
प्रदर्शित छवि फ़ाइल में संग्रहीत की तुलना में क्यों होगी?
यह शायद असंबंधित समस्या है, लेकिन अपने init विधि है, बताए 'स्वयं = के बाद और अधिक परंपरागत होगा [सुपर initWithImage: छवि]', आप जांच चाहे स्वयं शून्य है, और यदि यह है, तुरंत वापस लौटें। यदि स्वयं कभी शून्य हो, तो यह इसलिए है क्योंकि (1) अभिभावक का प्रारंभिक स्वयं ठीक से प्रारंभ नहीं कर सका, या (2) आवंटित कुछ अजीब स्मृति स्थिति (अत्यंत दुर्लभ) की वजह से शून्य वापस आ गया। यह अच्छी रक्षात्मक प्रोग्रामिंग अभ्यास है। –
नोट के लिए धन्यवाद, मैं इसे आजमाउंगा। –