Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UITableViewCell ImageView上的Xamarin.iOS圆角_Ios_Uitableview_Uiimageview_Xamarin.ios - Fatal编程技术网

UITableViewCell ImageView上的Xamarin.iOS圆角

UITableViewCell ImageView上的Xamarin.iOS圆角,ios,uitableview,uiimageview,xamarin.ios,Ios,Uitableview,Uiimageview,Xamarin.ios,我有一个带有ImageView的UITableCell。我试图给那个图像视图圆角。我尝试了以下方法: cell.ImageView.ClipsToBounds = true; cell.ImageView.Layer.BorderWidth = 1; cell.ImageView.Layer.MasksToBounds = true; cell.ImageView.Layer.CornerRadius = 20; 但这没有任何效果。有人能用代码示例解释或演示如何

我有一个带有ImageView的UITableCell。我试图给那个图像视图圆角。我尝试了以下方法:

    cell.ImageView.ClipsToBounds = true;
    cell.ImageView.Layer.BorderWidth = 1;
    cell.ImageView.Layer.MasksToBounds = true;
    cell.ImageView.Layer.CornerRadius = 20;
但这没有任何效果。有人能用代码示例解释或演示如何实现这种效果吗

cell.ImageView.Layer.BorderWidth = 1;
cell.ImageView.Layer.CornerRadius = 20; 
cell.ImageView.Layer.MasksToBounds = true;
试着在最后遮住边界


试着在最后遮住边界。

另一个问题啊,但它应该像你做的一样工作正常,有一个屏幕截图,所以只要指出问题所在,我就可以帮助你


或者只是发布你所做的更详细的代码,然后我也许可以找到问题。

另一个问题啊,但它应该像你做的一样工作正常,有一个屏幕截图,所以只要指出问题所在,我就可以帮你

或者只发布您所做的更多详细代码,然后我可能会发现问题。

ViewCellRenderer
  • 首先创建listview

    namespace  MaxenceTest.Renderers  
        {  
            public  class  MyViewCell  :  ViewCell  
            {  
                public  static  BindableProperty  CornerRadiusProperty  =               BindableProperty.Create(nameof(CornerRadius),  typeof(double),  typeof(MyViewCell),default(double));  
                public  double  CornerRadius  
                {  
                    get  {  return  (double)GetValue(CornerRadiusProperty);  }  
                    set  {  SetValue(CornerRadiusProperty,  value);  }  
                }  
    
            public  static  BindableProperty  BackgroundColorProperty  =  BindableProperty.Create(nameof(BackgroundColor),  typeof(Color),  typeof(MyViewCell),  default(Color));  
            public  Color  BackgroundColor  
            {  
                get  {  return  (Color)GetValue(BackgroundColorProperty);  }  
                set  {  SetValue(BackgroundColorProperty,  value);  }  
            }  
        }  
    }
    
  • 在Xamarin iOS项目中实现它

    [assembly:  ExportRenderer(typeof(MyViewCell),  typeof(MyViewCellIOS))\]  
    namespace  MaxenceTest.iOS.Renderers  
    {  
        public  class  MyViewCellIOS  :  ViewCellRenderer  
        {  
            public  override  UITableViewCell  GetCell(Cell  item,              UITableViewCell  reusableCell,  UITableView  tv)  
            {  
                UITableViewCell  viewCell  =  base.GetCell(item,  reusableCell,  tv);  
                if(viewCell  !=  null)  
                {  
                    if(item  is  MyViewCell  mycell)  
                    {  
                        UIView  custom  =  new  UIView();  
                        viewCell.ContentView.Layer.BackgroundColor  =                       mycell.BackgroundColor.ToCGColor();  
                        viewCell.ContentView.Layer.CornerRadius  =  new  nfloat(mycell.CornerRadius);  
                    }  
                }  
                return  viewCell;  
            }  
        }  
    }
    
  • 在XXML中使用它

                    <StackLayout  BackgroundColor="Transparent">  
                        <ListView  
                            x:Name="list"  
                            BackgroundColor="Transparent"  
                            SeparatorColor="Transparent"  
                            SeparatorVisibility="None"  
                            HasUnevenRows="true">  
                            <ListView.ItemTemplate>  
                                <DataTemplate>  
                                    <myControls:MyViewCell  CornerRadius="20"       BackgroundColor="Fuchsia">  
                                        <Grid>  
                                            <Grid.RowDefinitions>  
                                                <RowDefinition  Height="*"/>  
                                            </Grid.RowDefinitions>      
                                            <StackLayout  Margin="10">  
                                                <Label  FontSize="20"  TextColor="White"    FontAttributes="Bold"  Text="{Binding  title}"/>  
                                                <Label  FontSize="15"  TextColor="White"  Text="{Binding  resume}"/>  
                                            </StackLayout>  
                                        </Grid>  
                                    </myControls:MyViewCell>  
                                </DataTemplate>  
                            </ListView.ItemTemplate>  
                        </ListView>  
                    </StackLayout>
    
    
    
  • 享受

  • ViewCell渲染器
  • 首先创建listview

    namespace  MaxenceTest.Renderers  
        {  
            public  class  MyViewCell  :  ViewCell  
            {  
                public  static  BindableProperty  CornerRadiusProperty  =               BindableProperty.Create(nameof(CornerRadius),  typeof(double),  typeof(MyViewCell),default(double));  
                public  double  CornerRadius  
                {  
                    get  {  return  (double)GetValue(CornerRadiusProperty);  }  
                    set  {  SetValue(CornerRadiusProperty,  value);  }  
                }  
    
            public  static  BindableProperty  BackgroundColorProperty  =  BindableProperty.Create(nameof(BackgroundColor),  typeof(Color),  typeof(MyViewCell),  default(Color));  
            public  Color  BackgroundColor  
            {  
                get  {  return  (Color)GetValue(BackgroundColorProperty);  }  
                set  {  SetValue(BackgroundColorProperty,  value);  }  
            }  
        }  
    }
    
  • 在Xamarin iOS项目中实现它

    [assembly:  ExportRenderer(typeof(MyViewCell),  typeof(MyViewCellIOS))\]  
    namespace  MaxenceTest.iOS.Renderers  
    {  
        public  class  MyViewCellIOS  :  ViewCellRenderer  
        {  
            public  override  UITableViewCell  GetCell(Cell  item,              UITableViewCell  reusableCell,  UITableView  tv)  
            {  
                UITableViewCell  viewCell  =  base.GetCell(item,  reusableCell,  tv);  
                if(viewCell  !=  null)  
                {  
                    if(item  is  MyViewCell  mycell)  
                    {  
                        UIView  custom  =  new  UIView();  
                        viewCell.ContentView.Layer.BackgroundColor  =                       mycell.BackgroundColor.ToCGColor();  
                        viewCell.ContentView.Layer.CornerRadius  =  new  nfloat(mycell.CornerRadius);  
                    }  
                }  
                return  viewCell;  
            }  
        }  
    }
    
  • 在XXML中使用它

                    <StackLayout  BackgroundColor="Transparent">  
                        <ListView  
                            x:Name="list"  
                            BackgroundColor="Transparent"  
                            SeparatorColor="Transparent"  
                            SeparatorVisibility="None"  
                            HasUnevenRows="true">  
                            <ListView.ItemTemplate>  
                                <DataTemplate>  
                                    <myControls:MyViewCell  CornerRadius="20"       BackgroundColor="Fuchsia">  
                                        <Grid>  
                                            <Grid.RowDefinitions>  
                                                <RowDefinition  Height="*"/>  
                                            </Grid.RowDefinitions>      
                                            <StackLayout  Margin="10">  
                                                <Label  FontSize="20"  TextColor="White"    FontAttributes="Bold"  Text="{Binding  title}"/>  
                                                <Label  FontSize="15"  TextColor="White"  Text="{Binding  resume}"/>  
                                            </StackLayout>  
                                        </Grid>  
                                    </myControls:MyViewCell>  
                                </DataTemplate>  
                            </ListView.ItemTemplate>  
                        </ListView>  
                    </StackLayout>
    
    
    
  • 享受


  • 嗨,埃夫根尼,这没有效果。图像仍呈现为无圆角。请尝试不使用
    cell.ImageView.ClipsToBounds=true代码行。。。请发表评论,然后再试一次。嗨,埃夫根尼,这没有效果。图像仍呈现为无圆角。请尝试不使用
    cell.ImageView.ClipsToBounds=true代码行。。。我想问题是因为我扩展了UITableViewCell,我在自定义UITableViewCell的构造函数中添加了圆角代码,现在它可以工作了!啊,我想问题是因为我扩展了UITableViewCell,我在自定义UITableViewCell的构造函数中添加了圆角代码,现在它可以工作了!