xamarin.ios 半圆角按钮Readerer
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的更多相关文章
- xamarin UWP自定义圆角按钮
uwp自带的button本身不支持圆角属性,所以要通过自定义控件实现. 通过设置Button的Background=“{x:Null}”设置为Null使背景为空,再设置Button.Content中的 ...
- Xamarin iOS教程之使用按钮接接收用户输入
Xamarin iOS教程之使用按钮接接收用户输入 Xamarin iOS使用按钮接接收用户输入 按钮是用户交互的最基础控件.即使是在iPhone或者iPad中,用户使用最多操作也是通过触摸实现点击. ...
- iOS中创建自定义的圆角按钮
iOS中很多时候都需要用到指定风格的圆角按钮,尽管UIButton提供了一个方式创建圆角按钮: + (id)buttonWithType:(UIButtonType)buttonType;//指定bu ...
- iOS控件圆角与半圆角
开发过程中难免用到圆角以及恶心的半圆角,看代码 半圆角:这是把左边的两个角切成了圆角 UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoun ...
- Xamarin Studio在Mac环境下的配置和Xamarin.iOS常用控件的示例
看过好多帖子都是Win环境装XS,Mac只是个模拟器,讲解在Mac环境下如何配置Xamarin Studio很少,也是一点点找资料,东拼西凑才把Xamarin Studio装在Mac上跑起来,如下: ...
- Xamarin.IOS之多视图
欢迎大家加入以下开源社区 Xamarin-Cn:https://github.com/Xamarin-Cn Mvvmcross-Cn:https://github.com/Mvvmcross-Cn ...
- Xamarin.IOS之快速入门
欢迎大家加入以下开源社区 Xamarin-Cn:https://github.com/Xamarin-Cn Mvvmcross-Cn:https://github.com/Mvvmcross-Cn ...
- Xamarin iOS编写第一个应用程序创建工程
Xamarin iOS编写第一个应用程序创建工程 在Xcode以及Xamarin安装好后,就可以在Xamarin Studio中编写程序了.本节将主要讲解在Xamarin Studio中如何进行工程的 ...
- iOS Simulator功能介绍关于Xamarin IOS开发
iOS Simulator功能介绍关于Xamarin IOS开发 iOS Simulator功能介绍 在图1.38所示的运行效果中,所见到的类似于手机的模型就是iOS Simulator.在没有iPh ...
随机推荐
- Java并发之(2):线程通信wait/notify(TIJ_21_5)
简介: java中线程间同步的最基本的方式就是使用wait()¬ify()¬ifyAll(),它们是线程间的握手机制.除了上述方法,java5还在java.util.con ...
- 【转】 [UnityUI]UGUI射线检测
http://blog.csdn.net/lyh916/article/details/50947026 1.Graphic Raycaster 主要用于UI上的射线检测,挂有这个组件的物体,必须要挂 ...
- UNet简单案例讲解
1.创建文件夹: 2.创建一个空物体,添加如下组件: Network Manager(网络管理组件): Network Manager HUD(提供一个UI): 3.创建如下模型,并设置为预制体: 给 ...
- Start state is missing. Add at least one state to the flow
springmvc配置过程中,会配置数据库文件,比如说如下文件:这个时候可能会出现“Start state is missing. Add at least one state to the flow ...
- 使用SS5搭建linux下的sock5代理服务器
http://sourceforge.net/projects/ss5/下载最新源码 apt-get install libpam0g-dev apt-get install libldap2-dev ...
- POJ 2763 Housewife Wind(DFS序+LCA+树状数组)
Housewife Wind Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 11419 Accepted: 3140 D ...
- UIImage与Base64相互转换
UIImage与Base64相互转换 采用第三方类 Address:https://github.com/l4u/NSData-Base64/ 经测试好用. 2013-07-17
- repeater做成gridview【更新删除编辑等】
原文发布时间为:2009-06-14 -- 来源于本人的百度文章 [由搬家工具导入] 不多说,不会说。。看我做的范例。。。 http://download.csdn.net/source/138556 ...
- Linux Mint---安装篇
先前接触过Debian6,埋头折腾已经是好几年前的事情了,后来就放下了,现在工作之余时间比较多,正好debian8.1出来了,于是乎装了个debian用,结果,自己其实还是一个菜蛋而已,连软件源怎么设 ...
- angular 右击事件的写法
.directive('ngRightClick', function ($parse){ return function (scope, element, attrs){ var fn = $par ...