UIImage can be used to load images. However, if you want to zoom in or out an image, you cannot use UIImage. next we add a category of UIImage to zoom in or out the image in UIImage. 32. UIImage + Scale the image
UIImage can be used to load images. However, if you want to zoom in or out an image, you cannot use UIImage. next we add a category of UIImage to zoom in or out the image in UIImage.
First, create a UIImage + Scale class.
Then, the method to implement this class is as follows:
# Import
@ Interface UIImage (scale)-(UIImage *) scaleToSize :( CGSize) size; @ end # import "UIImage + Scale. h "@ implementation UIImage (scale)-(UIImage *) scaleToSize :( CGSize) size {// Create a bitmap context // and set it to the currently in use contextUIGraphicsBeginImageContext (size); // draw an image of varying size [self drawInRect: CGRectMake (0, 0, size. width, size. height)]; // Create a UIImage * scaledImage = UIGraphicsGetImageFromCurrentImageContext () from the current context; // make the current context output the stack UIGraphicsEndImageContext (); // return the new scaled image return scaledImage;} @ end
Finally, this class is used:
#import "UIImage+Scale.h"[[UIImage imageNamed:”p.png”] scaleToSize:CGSizeMake(252.0f,192.0f)];
33. Coreplot: in a scatter chart, legendTitleForBarPlot is not called.
LegendTitleForBarPlot is the data source method of the bar chart. this method is not available in the CPTScatterPlotDataSource commissioned by the data source of the scatter chart. The only way to customize the title of a legend is to specify the title attribute of the plot. If the title is empty, the identifier attribute is used.
34. setHidesBackButton cannot hide the return button
Move setHidesBackButton: animated: to viewDidAppear: method instead of the viewWillAppear: or viewDidLoad method.
35. cannotfind protocol declaration NSURLConnectionDelegate
IOS5 starts NSURLConnectionDelegate to be deprecated. in NSURLConnection. h, these methods become informal protocols. At the same time, a copy of these methods is copied to the formal protocol NSURLConnectionDataDelegate. You can directly declare the class interface Delete and implement these methods to use informal protocols.
36. warning "Property 'ssynthesized getter follows Cocoa naming convention for returning 'owner' objects"
In the attribute for synthesized, the attribute name cannot start with "new", for example, "newFeature ".
37. Implicit declaration of function 'XXX' is invalidin C99
This is a bug in Xcode. This error is reported when the compiler first sees the function definition but does not find the function prototype. The solution is to add the function prototype declaration before the function definition. Note: insert the function prototype declaration statement into the interface declaration of the class (. h header file), or before the class implementation statement (. m file ).
38.-[UIImageresizableImageWithCapInsets:]: unrecognized selector
This method is added in iOS5. In iOS4, use stretchableImageWithLeftCapWidth: topCapHeight: method. Code:
if([img respondsToSelector:@selector(resizableImageWithCapInsets:)]){//for iOS 5+img=[srcImg resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)]; }else{//iOS 4 compatibilityimg=[srcImg stretchableImageWithLeftCapWidth:6 topCapHeight:0];}
39. calculate the string Size of the specified font
CGSizemaximumLabelSize = CGSizeMake(250 ,MAXFLOAT);CGSizeexpectedLabelSize = [LABEL.text sizeWithFont:[UIFontsystemFontOfSize:UILabel.font]constrainedToSize:maximumLabelSizelineBreakMode:UILineBreakModeWordWrap];
ExpectedLabelSize is the actual size calculated based on the font, maximum Size limit, and line feed mode.
40. ASIHTTPRequestclearDelegateAndCancel method causes program crash
ASIHTTPRequest does not hold the delegate object. when you cancel a request or delegate release, we should cancel the request to avoid calling the released delegate method. However, the clearDelegateAndCancel method will cause an error and crash when calling the deallocated object.
To avoid this, you should (for version 1.8.1 and earlier ):
Hold ASIHTTPRequest object in delegate;
When delegate is released or request is canceled, use [requestrelease], request = nil; "instead of calling clearDelegateAndCancel ;".
41. Castof 'int' to 'camediatimingfunction * 'is disallowed with ARC
The following code causes the preceding error:
transition.timingFunction= UIViewAnimationCurveEaseInOut;
In fact, this code is incorrect even in MRC (manual memory management. The error does not occur because the value of UIViewAnimationCurveEaseInOut is usually 0, which is converted to nil. In fact, this code should be modified:
[animationsetTimingFunction:[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
The above is the content of iOS development FAQ (4). For more information, please follow the PHP Chinese network (www.php1.cn )!