gpt4 book ai didi

iphone - 左侧单点触控 iPhone 上带圆角的 UIImage

转载 作者:行者123 更新时间:2023-12-03 21:02:05 24 4
gpt4 key购买 nike

我想为我的表格 View 创建一个单元格,如下图所示:

enter image description here

如您所见,在这个单元格中我有一个 UIImage,其左侧有一些圆角。我使用此代码将角半径添加到我的 UIImage:

    ThumbnailImg .Layer .CornerRadius = 7.0f;
ThumbnailImg .Layer .MasksToBounds = true ;

但我不知道如何为 uiimage 的左侧设置半径。

我猜想的另一个解决方案是更改 uiimageview ,使其左角与单元格的角匹配(我在每个部分中使用分组表宽度 1 行),因此边框将自动创建。但对于这种方式,我也不知道我应该做什么:-s。

我也找到了 Objective-C 的这个解决方案。任何人都可以帮助在单点触控 iPhone 上使用此功能吗?

https://stackoverflow.com/a/4930166

最佳答案

子类UIImageView以允许它通过UIBezierPath绘制所需的圆角。

UIView 示例:

public class UIViewCustomRounded: UIView
{
// Inspired by:
// https://stackoverflow.com/questions/4847163/round-two-corners-in-uiview
// https://stackoverflow.com/questions/2264083/rounded-uiview-using-calayers-only-some-corners-how/
public UIViewCustomRounded (): base()
{
}

/// <summary>
/// Sets the corners.
/// </summary>
/// <param name="corners">Corners.</param>
/// <param name="cornerRadius">Corner radius.</param>
public void SetCorners(UIRectCorner corners, float cornerRadius)
{
var maskLayer = new CAShapeLayer();
maskLayer.Frame = Bounds;
var roundedPath = UIBezierPath.FromRoundedRect(maskLayer.Bounds, corners, new SizeF(cornerRadius, cornerRadius));
// maskLayer.FillColor = UIColor.White.CGColor;
// maskLayer.BackgroundColor = UIColor.Clear.CGColor;
maskLayer.Path = roundedPath.CGPath;

//Don't add masks to layers already in the hierarchy!
Layer.Mask = maskLayer;
}
}

用法:

var a = new UIViewCustomRounded()
// Don't forget to set frame and add it as subview
a.SetCorners(UIRectCorner.BottomLeft | UIRectCorner.BottomRight, 10);

只要 UIImageViewUIView 的子类,它也应该适用于 UIImageView

Reference answer .

关于iphone - 左侧单点触控 iPhone 上带圆角的 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15849173/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com