微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/iOS/329634.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐