
例如,表中的第一个图像只需要左上角的四舍五入.
解决方法 这是我的解决方案,可以使用一些重构:voID addRoundedRecttopath(CGContextRef context,CGRect rect,float ovalWIDth,float ovalHeight,BOol top,BOol bottom){ float fw,fh; if (ovalWIDth == 0 || ovalHeight == 0) { CGContextAddRect(context,rect); return; } CGContextSaveGState(context); CGContextTranslateCTM (context,CGRectGetMinX(rect),CGRectGetMinY(rect)); CGContextScaleCTM (context,ovalWIDth,ovalHeight); fw = CGRectGetWIDth (rect) / ovalWIDth; fh = CGRectGetHeight (rect) / ovalHeight; CGContextMovetoPoint(context,fw,fh/2); CGContextAddArctopoint(context,fh,fw/2,0); NSLog(@"bottom? %d",bottom); if (top) { CGContextAddArctopoint(context,fh/2,3); } else { CGContextAddArctopoint(context,0); } if (bottom) { CGContextAddArctopoint(context,0); } CGContextAddArctopoint(context,0); CGContextClosePath(context); CGContextRestoreGState(context);}- (UIImage *)roundCornersOfImage:(UIImage *)source roundtop:(BOol)top roundBottom:(BOol)bottom { int w = source.size.wIDth; int h = source.size.height; CGcolorSpaceRef colorSpace = CGcolorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(NulL,w,h,8,4 * w,colorSpace,kCGImageAlphaPremultiplIEdFirst); CGContextBeginPath(context); CGRect rect = CGRectMake(0,h); addRoundedRecttopath(context,rect,4,top,bottom); CGContextClosePath(context); CGContextClip(context); CGContextDrawImage(context,CGRectMake(0,h),source.CGImage); CGImageRef imageMasked = CGBitmapContextCreateImage(context); CGContextRelease(context); CGcolorSpaceRelease(colorSpace); return [UIImage imageWithCGImage:imageMasked]; } 实现这些功能,然后检查cellForRowAtIndexPath委托方法中的indexPath,以确定要舍入的角.
if (indexPath.row == 0) { cell.imageVIEw.image = [self roundCornersOfImage:coverImage roundtop:YES roundBottom:NO]; } else if (indexPath.row == [indexPath length]) { cell.imageVIEw.image = [self roundCornersOfImage:coverImage roundtop:NO roundBottom:YES]; } else { cell.imageVIEw.image = coverImage; } 总结 以上是内存溢出为你收集整理的objective-c – 如何将UIImage添加到分组的UITableViewCell,以便圆角?全部内容,希望文章能够帮你解决objective-c – 如何将UIImage添加到分组的UITableViewCell,以便圆角?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)