CGContextStrokeRect只是绘制矩形的一面
我需要绘制一个充满颜色和边界的矩形…矩形正确填充颜色,但外部边框部分绘制,只是矩形的右侧绘制!
生成的UIImage将被用在UITableViewCell的imageView中。
- (UIImage *)legendItemWithColor:(UIColor *)color { UIGraphicsBeginImageContext(self.view.frame.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGRect outside = CGRectMake(128, 128, 128, 128); CGRect legend = CGRectInset(outside, 1, 1); NSLog(@"Outside: %@", NSStringFromCGRect(outside)); NSLog(@"Legend: %@", NSStringFromCGRect(legend)); CGContextSetFillColorWithColor(context, color.CGColor); CGContextFillRect(context, legend); CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor); CGContextStrokeRect(context, outside); UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIGraphicsPopContext(); return img; }
问题是,当您将self.view.frame.size传递给UIGraphicsBeginImageContext(),然后在数组中使用绘制的矩形时,它将被缩小,边框被混淆。 尝试只传递你需要的大小,即CGSizeMake(2 * 128 + 128 + 2,2 * 128 + 128 + 2)。 然后它显示确定
- 无法创build具有nil模型错误的NSPersistentStoreCoordinator
- 为什么arc4random()在将variables存储在variables中时performance不同?
- Quartz 2D drawRect方法(iPhone)
- Swift – Playground – 核心graphics/核心文本/自定义视图
- 如何用png-brush和UIBezierPath擦除一块UIImageView
- 在这个CGBitmapContextCreate中,为什么是bytesPerRow 0?
- iPhone的iOS如何翻转/reflection任何UIView的地方?
- 在iOS Core Graphics中,什么是graphicsContext?
- iOS:完整的360度旋转使用块,而不是CABasicAnimation
- 在iOS中使用Core Graphics绘制VU表
- 如何在iOS应用程序中编辑PDF文件?