ios - 绘制矩形Monotouch PaintCode

标签 ios objective-c xamarin.ios xamarin

我正在尝试为我的应用程序创建更好的UI,但是我陷入了困境。我的设计技能不好,所以我正在尝试PaintCode。
我想用用户名和密码组下面的阴影制作一个登录屏幕。

我不能使用UIView,所以我做了同样的事情,但是在PaintCode中使用了Rect。

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中,就可以始终准确地知道对象在最终应用程序中的结束位置。我不知道该继承什么,以及如何制作在用户名和密码框下方绘制的矩形。

最佳答案

创建一个继承自UIView的自定义类,然后重写Draw函数并将自定义代码放在此处。

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

在上面的示例中,如果要使用XCode设计器(或Xamarin Storyboard设计器)中的控件,则Register属性是必需的。

关于ios - 绘制矩形Monotouch PaintCode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24087862/

相关文章:

ios - 使用自动布局动画化 UILabel 宽度

iphone - 如何按价格对应用内购买的产品进行排序?

objective-c - Objective Zip 不适用于 iOS5.1 设备,无法正确解压缩

ios - Xamarin iOS UITableView.Source NullReferenceException

iphone - ios 上没有屏幕历史记录

c# - 如何分配 UIPopoverPresentationControllerDelegate

ios - 如何修复 window.open ('http://maps.apple.com/?q=' , '_system' )?

iphone 再次请求当前位置权限

ios - UITapGestureRecognizer : "Unrecognized selector sent to instance"

ios - 在 iOS8 中更改键盘中完成按钮的文本