2011-12-08 26 views
3

我使用MonoTouch.Dialog和幾個剖面創建了一個視圖。這些部分需要在其他部分之前添加圖像,但是我很努力將UIImage添加到第一部分之前的區域。將圖像添加到Monotouch.Dialog中的剖面

我該怎麼辦?我已經強調了RootElement中我希望圖像去的地方。

public void HomeScreen() 
    { 
     var root = CreateRoot_HomeScreen(); 

     var dv = new DialogViewController (root, true); 
     navigation.PushViewController (dv, true); 
    } 

    RootElement CreateRoot_HomeScreen() 
    { 
     // Set up the ImageView with the Logo in it 
     var logo = UIImage.FromFile("Images/logo.png"); 

     var imageView = new UIImageView(logo); 

     return new RootElement("iEngage"){ 
      // The Image should go here 
      new Section(){ 

      }, 
      new Section("") 
      { 
       new StyledStringElement ("Search", delegate{ Console.Write("Clicked"); }) 
      } 
     }; 
    } 

回答

6

這聽起來像是從MonoTouch中的樣品頁眉和頁腳。基本上,您添加的每個Section都有您可以設置的HeaderView屬性。

您的UIImageView可能被分配到此屬性,它會插入您的標識在部分。

例如(複製/粘貼DemoHeaderFooters.cs

 var section = new Section() { 
      HeaderView = new UIImageView (UIImage.FromFile ("caltemplate.png")), 
     }; 

然後你在代碼中使用本節:

return new RootElement("iEngage"){ 
     section, 
     new Section("") 
     { 
      new StyledStringElement ("Search", delegate{ Console.Write("Clicked"); }) 
     } 
    }; 
+0

感謝poupou。我試過這個,我得到了一個扭曲的圖像,這個圖像被拉伸/扭曲以適應剖面的寬度和高度。我可以在其他地方指定這些寬度和高度嗎? – Darbio

+0

poupou,我研究出如何通過設置UIImageView的框架屬性來改變高度 - 謝謝。 – Darbio

+0

很高興你收到了,不要猶豫,編輯我的答案,並添加這個,如果你認爲它會幫助人們! – poupou