xamarin.from上可以使用本身的button实现圆角带图标的按钮,但是没有半圆角的按钮实现,需要自己使用Renderer重新写过来重写一个button。

下面是一个重写的带边框的方式,代码如下:

 using UIKit;
using Xamarin.Forms.Platform.iOS;
using Xamarin.Forms;
using CoreAnimation;
using System.ComponentModel; [assembly: ExportRenderer(typeof(Test.Renderers.MyRadiusButton), typeof(Test.iOS.Renderers.MyRadiusButton))]
namespace Test.iOS.Renderers
{
public class MyRadiusButton : ButtonRenderer
{
bool btnStatus = true;
bool radiusLeft = true;
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
Test.Renderers.MyRadiusButton view = Element as Test.Renderers.MyRadiusButton;
radiusLeft = view.RadiusLeft;
if (e.OldElement == null)
{
UIBezierPath maskPath; double widthLength = / - ;
maskPath = UIBezierPath.FromRoundedRect(new CoreGraphics.CGRect(, , widthLength, ), UIRectCorner.TopLeft | UIRectCorner.BottomLeft, new CoreGraphics.CGSize(, )); CAShapeLayer maskLayer = new CAShapeLayer();
//maskLayer.Frame = new CoreGraphics.CGRect(0, 0, widthLength, 35);
maskLayer.Path = maskPath.CGPath;
maskLayer.StrokeColor = new CoreGraphics.CGColor(, , );//边框颜色 CAShapeLayer borderLayer = new CAShapeLayer();
borderLayer.Path = maskPath.CGPath;
borderLayer.Frame = new CoreGraphics.CGRect(, , widthLength, );
borderLayer.FillColor = new CoreGraphics.CGColor(, , , 0f);
borderLayer.StrokeColor = new CoreGraphics.CGColor(0.23f, 0.72f, 0.47f, 1.0f);
borderLayer.LineWidth = ; Control.Layer.Mask = maskLayer;
Control.Layer.AddSublayer(borderLayer);
Control.Layer.MasksToBounds = true;
Control.SetTitleColor(UIColor.FromRGB(, , ), UIControlState.Normal);
Control.BackgroundColor = UIColor.FromRGB(, , ); view.Clicked += (sender, even) =>
{
if (!view.BtnSelected)
{
if (btnStatus)
{
Control.SetTitleColor(UIColor.FromRGB(, , ), UIControlState.Normal);
Control.BackgroundColor = UIColor.FromRGB(, , );
btnStatus = !btnStatus;
}
else
{
Control.SetTitleColor(UIColor.FromRGB(, , ), UIControlState.Normal);
Control.BackgroundColor = UIColor.FromRGB(, , );
btnStatus = !btnStatus;
}
view.BtnClickAction?.Invoke();
}
}; }
}
}
}

xamarin.ios 半圆角按钮Readerer的更多相关文章

  1. xamarin UWP自定义圆角按钮

    uwp自带的button本身不支持圆角属性,所以要通过自定义控件实现. 通过设置Button的Background=“{x:Null}”设置为Null使背景为空,再设置Button.Content中的 ...

  2. Xamarin iOS教程之使用按钮接接收用户输入

    Xamarin iOS教程之使用按钮接接收用户输入 Xamarin iOS使用按钮接接收用户输入 按钮是用户交互的最基础控件.即使是在iPhone或者iPad中,用户使用最多操作也是通过触摸实现点击. ...

  3. iOS中创建自定义的圆角按钮

    iOS中很多时候都需要用到指定风格的圆角按钮,尽管UIButton提供了一个方式创建圆角按钮: + (id)buttonWithType:(UIButtonType)buttonType;//指定bu ...

  4. iOS控件圆角与半圆角

    开发过程中难免用到圆角以及恶心的半圆角,看代码 半圆角:这是把左边的两个角切成了圆角 UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoun ...

  5. Xamarin Studio在Mac环境下的配置和Xamarin.iOS常用控件的示例

    看过好多帖子都是Win环境装XS,Mac只是个模拟器,讲解在Mac环境下如何配置Xamarin Studio很少,也是一点点找资料,东拼西凑才把Xamarin Studio装在Mac上跑起来,如下: ...

  6. Xamarin.IOS之多视图

    欢迎大家加入以下开源社区 Xamarin-Cn:https://github.com/Xamarin-Cn Mvvmcross-Cn:https://github.com/Mvvmcross-Cn  ...

  7. Xamarin.IOS之快速入门

    欢迎大家加入以下开源社区 Xamarin-Cn:https://github.com/Xamarin-Cn Mvvmcross-Cn:https://github.com/Mvvmcross-Cn  ...

  8. Xamarin iOS编写第一个应用程序创建工程

    Xamarin iOS编写第一个应用程序创建工程 在Xcode以及Xamarin安装好后,就可以在Xamarin Studio中编写程序了.本节将主要讲解在Xamarin Studio中如何进行工程的 ...

  9. iOS Simulator功能介绍关于Xamarin IOS开发

    iOS Simulator功能介绍关于Xamarin IOS开发 iOS Simulator功能介绍 在图1.38所示的运行效果中,所见到的类似于手机的模型就是iOS Simulator.在没有iPh ...

随机推荐

  1. Marketing learning-2

    Part three 1.strategies for leadership 1)operational excellence:operational competence 2)performance ...

  2. 精通CSS高级Web标准解决方案(7、布局)

    7.1 让设计居中 7.1.1 使用自动空白边让设计居中 <body> <div id="wrapper"> </div> </body& ...

  3. python3.x与python2.x的区别(转)

    转自:http://www.cnblogs.com/codingmylife/archive/2010/06/06/1752807.html 1.性能 Py3.0运行 pystone benchmar ...

  4. 【Luogu】P2491消防(单调队列)

    题目链接 首先可以想到路径一定是在直径上的. 然后对每个点dfs出不经过直径的以它开始的路径最大长度,记为dis 然后就可以求出直径之后枚举左右端点,设左端点l右端点r,直径上点距离直径上起点的距离用 ...

  5. Codeforces #1063C Dwarves, Hats and Extrasensory Abilities

    题目大意 交互题. 输出平面上的一个点的坐标,交互程序给这个点染色(白或黑). 如此重复 $n$ 次($ 1\le n \le 30$). 要求输出的 $n$ 个点各不相同,并且不论交互程序怎样给它们 ...

  6. Python之时间:time模块

    import time   对于时间,使用最频繁的模块 1.获取当前时间 (1)时间戳 time.time() 时间戳:从1970年1月1日0点开始到现在按秒计算的偏移量 (2)时间元组 time.l ...

  7. vue项目中使用vue-awesome

    公司在项目重构时,遇到图标问题,然后把vue-awesome.iconfont.iconMoon都试了一遍,虽然最终使用了iconMoon但是也要把这两个过程记录一下. github地址 1.首先安装 ...

  8. 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛部分题解

    A 跳台阶 思路:其实很简单,不过当时直接dp来做了 AC代码: #define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include& ...

  9. 洛谷 [P1552] 派遣

    树型DP + 可并堆 非常清楚的想到是树型DP, 但是如何维护最小值, 于是就去新学了可并堆 #include <iostream> #include <cstring> #i ...

  10. .NET泛型编程 性能提升工具 List<T>

    原文发布时间为:2009-10-27 -- 来源于本人的百度文章 [由搬家工具导入] 结论  .NET 2.0中的泛型是强有力的,你写的代码不必限定于一特定类型,然而你的代码却能具有类型安全性。泛型的 ...