2014-06-06 27 views
1

我想爲我的應用程序做一個更好的用戶界面,但我堅持在這。我的設計技巧不好,所以我正在嘗試PaintCode。 我想用這個陰影在用戶名和密碼組之下製作一個登錄屏幕。繪製矩形Monotouch PaintCode

Shadowed UiView

我不能使用一個UIView所以我做相同的,但在PaintCode使用矩形。

var context = UIGraphics.GetCurrentContext(); 
//// Shadow Declarations 
var shadow = UIColor.DarkGray.ColorWithAlpha(0.71f).CGColor; 
var shadowOffset = new SizeF(6.1f, 4.1f); 
var shadowBlurRadius = 5.0f; 

    //// Rectangle Drawing 
UIBezierPath rectanglePath = new UIBezierPath(); 
rectanglePath.MoveTo(new PointF(18.0f, 239.0f)); 
rectanglePath.AddLineTo(new PointF(383.0f, 239.0f)); 
rectanglePath.AddLineTo(new PointF(383.0f, 13.0f)); 
rectanglePath.AddLineTo(new PointF(18.0f, 13.0f)); 
rectanglePath.AddLineTo(new PointF(18.0f, 239.0f)); 
rectanglePath.ClosePath(); 
context.SaveState(); 
context.SetShadowWithColor(shadowOffset, shadowBlurRadius, shadow); 
UIColor.White.SetFill(); 
rectanglePath.Fill(); 
context.RestoreState(); 

現在我不知道如何處理該代碼。在教程和文檔中,他們通常會創建一個UIView,這樣他們只需創建一個UIView子類並將其添加到Interface Builder中,這樣您就可以始終確切地知道對象將在最終應用程序中結束的位置。我不知道如何劃分子類,以及如何在我的用戶名和密碼框下繪製矩形。

回答

3

創建一個繼承自UIView的自定義類,然後重寫Draw函數並將您的自定義代碼放在那裏。

[Register("DrawView")] 
public class DrawView : UIView 
{ 
    public override void Draw(System.Drawing.RectangleF rect) 
    { 

在上面的例子,如果你想使用的XCode設計師(或Xamarin故事板設計師)的控制寄存器屬性是必要的。