簡體   English   中英

我該怎么做 <TableSection> 在Apple iOS設置頁面上看起來像是帶有左側圖標的?

[英]How can I make my <TableSection> look like that on the Apple iOS Settings page with an icon on the left?

我有一個設置頁面代碼和一個自定義渲染器,如下所示,但我想做的是制作一個左側帶有圖標的文本單元,就像Apple在其“設置”頁面上一樣。

有誰知道我該怎么做?

<ContentPage.Content>
   <StackLayout>
      <TableView Intent="Settings" RowHeight="50" HasUnevenRows="true">
         <TableView.Root>
            <TableSection>
               <TextCell Text="English" StyleId="disclosure" Tapped="ABC"/>

            </TableSection>

            </TableSection>
        </TableView.Root>
      </TableView>
    </StackLayout>
 </ContentPage.Content>

我已經設置好了:

public class TextCellCustomRenderer : TextCellRenderer
{
    CellTableViewCell cell;
    public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
    {
        var textCell = (TextCell)item;
        var fullName = item.GetType().FullName;
        cell = tv.DequeueReusableCell(fullName) as CellTableViewCell;

        if (cell == null)
        {
            cell = new CellTableViewCell(UITableViewCellStyle.Value1, fullName);
        }
        else
        {
            cell.Cell.PropertyChanged -= cell.HandlePropertyChanged;
            //cell.Cell.PropertyChanged -= Current_PropertyChanged;
        }

        cell.Cell = textCell;
        textCell.PropertyChanged += cell.HandlePropertyChanged;
        cell.PropertyChanged = this.HandlePropertyChanged;
        cell.SelectionStyle = UITableViewCellSelectionStyle.None;
        cell.TextLabel.Text = textCell.Text;
        cell.DetailTextLabel.Text = textCell.Detail;
        cell.ContentView.BackgroundColor = UIColor.White;

        switch (item.StyleId)
        {
            case "checkmark":
                cell.Accessory = UIKit.UITableViewCellAccessory.Checkmark;
                break;
            case "detail-button":
                cell.Accessory = UIKit.UITableViewCellAccessory.DetailButton;
                break;
            case "detail-disclosure-button":
                cell.Accessory = UIKit.UITableViewCellAccessory.DetailDisclosureButton;
                break;
            case "disclosure":
                cell.Accessory = UIKit.UITableViewCellAccessory.DisclosureIndicator;
                break;
            case "none":
            default:
                cell.Accessory = UIKit.UITableViewCellAccessory.None;
                break;
        }

        //UpdateBackground(cell, item);

        return cell;
    }

}

請參考此示例

ViewCellRenderer更合適。

在該項目中,您只需要將圖像,文本代碼放在類NativeiOSCell和方法LayoutSubviews中,

public override void LayoutSubviews()
{
    base.LayoutSubviews();

    SubheadingLabel.Frame = new CGRect(100, 18, 100, 20);
    CellImageView.Frame = new CGRect(5, 4, 33, 33);
}

PS

  • 如果要更改文本, 數據源中修改GetList

  • 如果要更改圖像內容,請在CustomRenderer.iOS / Resources / Images文件夾中替換這些圖像。

這是我的考驗

在此處輸入圖片說明

暫無
暫無

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

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