日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ios view 切上部分圆角_ios – 具有圆角的UIView:如何正确剪辑子视图?

發布時間:2024/9/19 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ios view 切上部分圆角_ios – 具有圆角的UIView:如何正确剪辑子视图? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我創建了一個覆蓋drawRect的UIView子類,并使用AddArcToPoint()繪制圓角. (我不想使用圖層的角半徑屬性,因為我需要定義哪些角必須舍入.)

問題我不能得到:如果我添加一個子視圖(0 | 0),它隱藏我的圓角.任何想法如何解決這個問題?我想要很好地剪輯.

這是繪制圓角矩形的代碼.這是Monotouch,但任何開發人員都應該可以理解.

public override void Draw (RectangleF rect)

{

using (var oContext = UIGraphics.GetCurrentContext())

{

oContext.SetLineWidth (this.StrokeWidth);

oContext.SetStrokeColor (this.oStrokeColor.CGColor);

oContext.SetFillColor (this.oRectColor.CGColor);

RectangleF oRect = this.Bounds;

float fRadius = this.CornerRadius;

float fWidth = oRect.Width;

float fHeight = oRect.Height;

// Make sure corner radius isn't larger than half the shorter side.

if (fRadius > fWidth / 2.0f)

{

fRadius = fWidth / 2.0f;

}

if (fRadius > fHeight / 2.0f)

{

fRadius = fHeight / 2.0f;

}

float fMinX = oRect.GetMinX ();

float fMidX = oRect.GetMidX ();

float fMaxX = oRect.GetMaxX ();

float fMinY = oRect.GetMinY ();

float fMidY = oRect.GetMidY ();

float fMaxY = oRect.GetMaxY ();

// Move to left middle.

oContext.MoveTo (fMinX,fMidY);

// Arc to top middle.

oContext.AddArcToPoint (fMinX,fMinY,fMidX,(this.RoundCorners & ROUND_CORNERS.TopLeft) == ROUND_CORNERS.TopLeft ? fRadius : 0);

// Arc to right middle.

oContext.AddArcToPoint (fMaxX,fMaxX,fMidY,(this.RoundCorners & ROUND_CORNERS.TopRight) == ROUND_CORNERS.TopRight ? fRadius : 0);

// Arc to bottom middle.

oContext.AddArcToPoint (fMaxX,fMaxY,(this.RoundCorners & ROUND_CORNERS.BottomRight) == ROUND_CORNERS.BottomRight ? fRadius : 0);

// Arc to left middle.

oContext.AddArcToPoint (fMinX,fMinX,(this.RoundCorners & ROUND_CORNERS.BottomLeft) == ROUND_CORNERS.BottomLeft ? fRadius : 0);

// Draw the path.

oContext.ClosePath ();

oContext.DrawPath (CGPathDrawingMode.FillStroke);

}

}

編輯:

這是一段代碼,演示如何使用CALayer解決它.

private void UpdateMask()

{

UIBezierPath oMaskPath = UIBezierPath.FromRoundedRect (this.Bounds,this.eRoundedCorners,new SizeF (this.fCornerRadius,this.fCornerRadius));

CAShapeLayer oMaskLayer = new CAShapeLayer ();

oMaskLayer.Frame = this.Bounds;

oMaskLayer.Path = oMaskPath.CGPath;

this.Layer.Mask = oMaskLayer;

}

總結

以上是生活随笔為你收集整理的ios view 切上部分圆角_ios – 具有圆角的UIView:如何正确剪辑子视图?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。