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. Python机器学习数据挖掘工具sklearn安装和使用

    python借助pip安装第三方库,所以首先确保电脑上已成功安装了pip. 安装sklearn前需要先安装numpy.scipy和pandas等库.安装的方式有两种: 一.前往python的组件库页( ...

  2. order by 对null的处理

    [Oracle 结论] order by colum asc 时,null默认被放在最后order by colum desc 时,null默认被放在最前nulls first 时,强制null放在最 ...

  3. iOS动画-扩散波纹效果

    最终效果 实现思路 动画的表现形式是颜色以及大小的变化,整体效果可以看做多个单独的波纹效果的叠加.因此我们可以创建多个CALayer,分别赋予CABasicAnimation动画,组成最终的动画效果. ...

  4. Mysql实战之数据备份

    author:JevonWei 版权声明:原创作品 blog:http://119.23.52.191/ --- 数据备份和恢复 mysqldump 冷备份单库(不会创建新库,需要手动创建并指定导入数 ...

  5. proteus仿真 引脚显示电平变化但不能显示波形

    proteus仿真 引脚显示电平变化但不能显示波形 原来是没有选择通道问题,proteus默认优先使用A通道才会显示波形,如果优先使用B,C,D通道,需要选择...

  6. RTSP会话基本流程

    RTSP会话基本流程 RTSP交互流程: C表示RTSP客户端,S表示RTSP服务端 ① C->S: OPTION request //询问S有哪些方法可用 S->C: OPTION re ...

  7. webstorm配置autoprefix

    http://blog.csdn.net/pugongying520/article/details/52712639 配置图

  8. JavaScript (JS) 面向对象编程 浅析 (含对象、函数原型链、闭包解析)

    1. 构造函数原型对象:prototype ① 构造函数独立创建对象,消耗性能 function Person(name) { this.name = name; this.sayHello = fu ...

  9. python面试题目【转1】

    原文地址:https://www.usblog.cc/blog/post/justzhl/b5cc9a05c7d2 问题一:以下的代码的输出将是什么? 说出你的答案并解释. 1 2 3 4 5 6 7 ...

  10. CodeForces Round #402 (Div.2) A-E

    2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...