[英]Remove rounded corners on TextEntry in Xamarin.iOS with Xamarin Effect
[英]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;
嘗試在最后掩蓋邊界。
首先創建您的列表視圖
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; } } }
在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>
請享用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.