Xamarin.ios 我如何在Xamarin画圆圈?
各位开发者好, 我使用xamarin(monotouch)我想画一个圆形的图像视图,比如google plus个人资料图像或者其他的 我在网上搜索,但没有找到有用的东西 谁来帮帮我Xamarin.ios 我如何在Xamarin画圆圈?,xamarin.ios,xamarin,draw,Xamarin.ios,Xamarin,Draw,各位开发者好, 我使用xamarin(monotouch)我想画一个圆形的图像视图,比如google plus个人资料图像或者其他的 我在网上搜索,但没有找到有用的东西 谁来帮帮我 谢谢..Xamarin.iOS是用户界面上Cocoa Touch的包装 所以要画圆,你需要使用Cocoa Touch API,也称为CoreGraphics 出于您的目的,您可以使用ui查看或ui按钮。使用ui按钮更容易处理触摸事件 基本思想是创建一个具有特定坐标和大小的UIButton,并将CornerRadiu
谢谢..Xamarin.iOS是用户界面上Cocoa Touch的包装 所以要画圆,你需要使用Cocoa Touch API,也称为CoreGraphics
出于您的目的,您可以使用
ui查看
或ui按钮
。使用ui按钮
更容易处理触摸事件
基本思想是创建一个具有特定坐标和大小的UIButton
,并将CornerRadius
属性设置为UIButton
大小的一半(假设要绘制一个圆,宽度和高度将相同)
您的代码可能如下所示(在UIViewController的ViewDidLoad
中):
最后实现事件处理程序(在UIViewController
中的某个位置定义此方法):
// define coordinates and size of the circular view
float x = 50;
float y = 50;
float width = 200;
float height = width;
// corner radius needs to be one half of the size of the view
float cornerRadius = width / 2;
RectangleF frame = new RectangleF(x, y, width, height);
// initialize button
UIButton circularView = new UIButton(frame);
// set corner radius
circularView.Layer.CornerRadius = cornerRadius;
// set background color, border color and width to see the circular view
circularView.BackgroundColor = UIColor.White;
circularView.Layer.CornerRadius = cornerRadius;
circularView.Layer.BorderColor = UIColor.Red.CGColor;
circularView.Layer.BorderWidth = 5;
// handle touch up inside event of the button
circularView.TouchUpInside += HandleCircularViewTouchUpInside;
// add button to view controller
this.View.Add(circularView);
private void HandleCircularViewTouchUpInside(object sender, EventArgs e)
{
// initialize random
Random rand = new Random(DateTime.Now.Millisecond);
// when the user 'clicks' on the circular view, randomly change the border color of the view
(sender as UIButton).Layer.BorderColor = UIColor.FromRGB(rand.Next(255), rand.Next(255), rand.Next(255)).CGColor;
}
我自己找到了解决方案。谢谢:)这个解决方案看起来怎么样?请发布你的答案。很高兴听到:-)。您可以创建自己的答案,并在几天后接受它。