iphone中的圆形相框效果
原问题来自于CSDN问答频道,更多解决方案见:http://ask.csdn.net/questions/1908想用下面的代码实现一个圆形相框:
CGContextRef context = CGBitmapContextCreate(NULL, self.bounds.size.width, self.bounds.size.height, 8, 4 * self.bounds.size.width, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedFirst);
CGContextAddArc(context, 1024/2, 768/2, size, 0, 6.3, 0);
CGContextClosePath(context);
CGContextClip(context);
CGContextDrawImage(context, self.bounds, imageView.image.CGImage);
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
UIImage *newImage = [UIImage imageWithCGImage:imageMasked];
CGImageRelease(imageMasked);
[imageView setImage:newImage];
UIGraphicsEndImageContext();
在设置size--,圆形区域就会缩小,但是设置size++的时候,就没有反应。
不知道怎么呢?
解决方案:
你的代码修改成这样就可以了
- (IBAction)minus:(id)sender {iphone --------------------编程问答-------------------- 除 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 这是C的吗,还是C++的 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 楼主牛啊,学习了 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- hao ren a --------------------编程问答-------------------- 对于 apple 一直怀有种 佩服崇敬的心理。
self.radius = @([self.radius floatValue]+10.0f);
[self redrawImage];
}
- (IBAction)plus:(id)sender {
self.radius = @([self.radius floatValue]-10.0f);
[self redrawImage];
}
-(void)redrawImage
{
//set the original image first
[_imageView setImage:[UIImage imageNamed:@"your image goes here"]];
CGFloat size = [self.radius floatValue];
CGContextRef context = CGBitmapContextCreate(NULL, self.view.bounds.size.width, self.view.bounds.size.height, 8, 4 * self.view.bounds.size.width, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedFirst);
CGContextAddArc(context, 320/2, 460/2, size, 0, 2*M_PI, 0);
CGContextClosePath(context);
CGContextClip(context);
CGContextDrawImage(context, self.view.bounds, _imageView.image.CGImage);
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
UIImage *newImage = [UIImage imageWithCGImage:imageMasked];
CGImageRelease(imageMasked);
[_imageView setImage:newImage];
UIGraphicsEndImageContext();
}
可是,舆论导向啊……最近不是很好吧? --------------------编程问答-------------------- --------------------编程问答-------------------- 学习了,不错 --------------------编程问答-------------------- 不错,学习了 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 好! --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 初来乍到。。for test 。。。见谅。。。 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 不错、、、、、 --------------------编程问答-------------------- --------------------编程问答-------------------- 看不懂,还是纯支持 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 貌似可以啊!!!! --------------------编程问答-------------------- 不懂 怎么弄 --------------------编程问答-------------------- --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 这是C的吗。。。。。。 --------------------编程问答-------------------- --------------------编程问答--------------------
那段代码是c吗?(新人,望指教) --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 不错!!!顶! --------------------编程问答-------------------- 高水平,顶起来 --------------------编程问答-------------------- 能发是否能 --------------------编程问答-------------------- Objective C --------------------编程问答-------------------- --------------------编程问答-------------------- 真不错 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 不错哦!!! --------------------编程问答-------------------- 看不懂,悲催的。。。。 --------------------编程问答-------------------- 用不着这么麻烦
--------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答--------------------
#import <QuartzCore/QuartzCore.h>
// ...
[image.layer setCornerRadius:17];
[image.layer setMasksToBounds:TRUE];
Objective C 上百度google一下吧 --------------------编程问答-------------------- 无满意结贴,来接分的 --------------------编程问答-------------------- 楼主牛啊,学习了 --------------------编程问答-------------------- 顶,楼主牛人,膜拜 --------------------编程问答--------------------
补充:移动开发 , iPhone