簡體   English   中英

Xamarin.iOS UITableViewCell ImageView上的圓角

[英]Xamarin.iOS Rounded corners on UITableViewCell ImageView

我有一個具有ImageView的UITableCell。 我試圖給ImageView圓角。 我嘗試了以下方法:

    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

  1. 首先創建您的列表視圖

     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); } } } } 
  2. 在您的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; } } } 
  3. 在xcml中使用

      <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> 
  4. 請享用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM