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

标签 iphone uitableview xamarin.ios uiimageview

我想为我的表格 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/

相关文章:

iphone - 无法以编程方式设置键盘类型 - ios

iphone - 获取正在平移的 View 的字典键并将其添加到数组中

objective-c - 调整 UITableView 的大小

ios - 获取 UISearchBar 的 tableView

ios - 单色触摸 : RegisterClassForCellReuse in UITAbleView throws NSInvalidArgumentException

iphone - 如何让NSUserDefaults显示在iPhone的设置中?

ios - 使用 Facebook 登录时出错

iphone - 当 deviceOrientation 改变时重新加载 UITableView 中的数据

ios - 如何使用由枚举组成的可变参数绑定(bind)方法

ios - Xamarin:UICollection 图像重新排序问题