ios – 绘制在UIView之外

前端之家收集整理的这篇文章主要介绍了ios – 绘制在UIView之外前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个UIView,我想画一个延伸过UIView框架的圆,
我已经将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];

}

解决方法

http://developer.apple.com/library/ios/#documentation/general/conceptual/Devpedia-CocoaApp/DrawingModel.html

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中做的是不可能的:

猜你在找的iOS相关文章