如何调用接受3个参数的静态方法

时间:2015-11-17 13:16:49

标签: ios objective-c

如何调用此功能? 我试图从-viewDidLoad调用此函数。 我试过了[circularImageWithImage(imageView.image, myclor, 0.2)];

static UIImage *circularImageWithImage(UIImage *inputImage,
                                       UIColor *borderColor,
                                       CGFloat borderWidth)
    {

    CGRect rect = (CGRect){ .origin=CGPointZero, .size=inputImage.size };

    UIGraphicsBeginImageContextWithOptions(rect.size, NO, inputImage.scale); {

        // Fill the entire circle with the border color.
        [borderColor setFill];
        [[UIBezierPath bezierPathWithOvalInRect:rect] fill];

        // Clip to the interior of the circle (inside the border).
        CGRect interiorBox = CGRectInset(rect, borderWidth, borderWidth);
        UIBezierPath *interior = [UIBezierPath bezierPathWithOvalInRect:interiorBox];
        [interior addClip];

        [inputImage drawInRect:rect];

    }

    UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return outputImage;
}

2 个答案:

答案 0 :(得分:0)

UIImage *sample = circularImageWithImage(imageView.image, myclor, 0.2);

答案 1 :(得分:0)

您可以尝试使用此代码。

UIImage *image = [UIImage imageNamed:@"yourImage.png"];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];//set your frame
//imageView.center = self.view.center;


UIImage *modifiedImage = circularImageWithImage(image, [UIColor redColor], 1.2);//border width >= 1.0 is better. Otherwise you may not see this
imageView.image = modifiedImage;
[self.view addSubview:imageView];