我已经将maskToBounds设置为NO – 期望我可以在UIView的边界之外画出右边和底部5个像素.
我期望椭圆形不被剪裁,但它确实被剪除,不会超出界限.
- (void)drawRect:(CGRect)rect { int width = self.bounds.size.width; int height = self.bounds.size.height; self.layer.masksToBounds = NO; //// Rounded Rectangle Drawing //// Oval Drawing UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(0,width+5,height+5)]; [[UIColor magentaColor] setFill]; [ovalPath fill]; [[UIColor blackColor] setStroke]; ovalPath.lineWidth = 1; [ovalPath stroke]; }
解决方法
UIView and NSView automatically configure the drawing environment of a
view before its drawRect: method is invoked. (In the AppKit framework,
configuring the drawing environment is called locking focus.) As part
of this configuration,the view class creates a graphics context for
the current drawing environment.This graphics context is a Quartz object (CGContext) that contains
information the drawing system requires,such as the colors to apply,
the drawing mode (stroke or fill),line width and style information,
font information,and compositing options. (In the AppKit,an object
of the NSGraphicsContext class wraps a CGContext object.) A graphics
context object is associated with a window,bitmap,PDF file,or other
output device and maintains information about the current state of the
drawing environment for that entity. A view draws using a graphics
context associated with the view’s window. For a view,the graphics
context sets the default clipping region to coincide with the view’s
bounds and puts the default drawing origin at the origin of a view’s
boundaries.
一旦剪辑区域被设置,你只能使它更小.那么你在UIView drawRect中做的是不可能的: