32. UIImage+Scale scaling pictures
UIImage can load pictures, but we want to get a reduced or enlarged picture, which cannot be done using UIImage. Next, we add a UIImage classification to implement UIImage. Picture zoom in and out.
First, create a UIImage+Scale class.
Then, implement the method of this class:
#import <UIKit/UIKit.h> @interface UIImage (scale) -(UIImage*)scaleToSize:(CGSize)size; @end #import "UIImage+Scale.h" @implementation UIImage (scale) -(UIImage*)scaleToSize:(CGSize)size { // 创建一个bitmap的context // 并把它设置成为当前正在使用的context UIGraphicsBeginImageContext(size); // 绘制改变大小的图片 [self drawInRect:CGRectMake(0, 0, size.width,size.height)]; // 从当前context中创建一个改变大小后的图片 UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); // 使当前的context出堆栈 UIGraphicsEndImageContext(); // 返回新的改变大小后的图片 return scaledImage; } @end
Finally, the use of this class:
#import "UIImage+Scale.h" [[UIImage imageNamed:”p.png”] scaleToSize:CGSizeMake(252.0f,192.0f)];
33. Coreplot: In a scatter plot, legendTitleForBarPlot will not be called
legendTitleForBarPlot is the data source method of the histogram. There is no such method in the data source delegate CPTScatterPlotDataSource of the scatter chart. The only way to customize the legend's title is to specify the plot's title attribute. If title is empty, the identifier attribute is used.
34. setHidesBackButton cannot hide the return button
Move setHidesBackButton:animated: to the viewDidAppear: method, not to the viewWillAppear: or viewDidLoad method.
35. cannot find protocol declaration NSURLConnectionDelegate
Starting from iOS5, NSURLConnectionDelegate was deprecated. In NSURLConnection.h, these methods became informal protocols. At the same time, a copy of these methods is copied into the official protocol NSURLConnectionDataDelegate. You can directly delete the
36. Warning "Property'ssynthesized getter follows Cocoa naming convention for returning 'owned'objects"
Among properties to be synthesized, the property name must not start with "new", such as "newFeature".
37. Implicit declaration of function 'xxx' is invalidin C99
This is a bug in Xcode. This error will be reported when the compiler sees a function definition for the first time but does not find the function prototype. The solution is to add the function prototype declaration before the function definition. Note that the function prototype declaration statement is inserted 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 new in iOS5. Please use the stretchableImageWithLeftCapWidth:topCapHeight: method in iOS4. Code:
if([img respondsToSelector:@selector(resizableImageWithCapInsets:)]) {//for iOS 5+ img=[srcImg resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)]; }else{//iOS 4 compatibility img=[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:maximumLabelSize lineBreakMode:UILineBreakModeWordWrap];
expectedLabelSize is the actual Size calculated based on the font, maximum size limit, and line break mode.
40. The ASIHTTPRequest clearDelegateAndCancel method causes the program to crash
ASIHTTPRequest does not hold the delegate object. When you cancel a request or release the delegate, in order to avoid calling the released delegate method, we should cancel the request. But the clearDelegateAndCancel method will cause a call deallocated object error and crash.
To avoid this, you should (for versions 1.8.1 and earlier):
Hold the ASIHTTPRequest object in the delegate;
When releasing the delegate or canceling the request, do not call clearDelegateAndCancel but use " [requestrelease],request=nil;".
41. Castof 'int' to 'CAMediaTimingFunction *' is disallowed with ARC
The following code causes the above error:
transition.timingFunction= UIViewAnimationCurveEaseInOut;
In fact, even in MRC (manual memory management), This code is also incorrect. The reason why there is no error is that UIViewAnimationCurveEaseInOut is usually 0, and it becomes nil when converted. In fact, this code should be modified to:
[animationsetTimingFunction:[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
The above is the content of iOS Development Questions (4). For more related content, please pay attention to the PHP Chinese website (www.php .cn)!