Xamarin.iOS 下拉刷新样式的修改
2016-12-08 17:22
225 查看
MvvmCross框架 提供了下拉刷新的控件:RefreshTableHeaderView,也就是一个View,但是前几天做项目的时候发现她的样式没办法修改。它内部控件展示的都是一些英文,而且没有左侧下拉箭头的样式。
最后翻看他的源码,发现这个类中一些主要的方法可以复写,于是我决定复写他的方法修改样式。
首先ViewController要继承自DialogViewController,复写MakeRefreshTableHeaderView方法:
/// <summary>
/// 重写创建刷新view的方法
/// </summary>
/// <returns>The refresh table header view.</returns>
/// <param name="rect">Rect.</param>
public override RefreshTableHeaderView MakeRefreshTableHeaderView(CoreGraphics.CGRect rect)
{
var headView = new BabyRefreshHeadView(rect);
return headView;
}
其中BabyRefreshHeadView是继承自系统提供的RefreshTableHeaderView,代码在下面,下一步是在ViewController中指定刷新事件:
//刷新方法
RefreshRequested += delegate {
ViewModel.LoadLatestDataList();
};
在构造方法或者页面加载方法中都可以。
最后贴上继承自RefreshTableHeaderView的类,在其中自定义我们自己想要的语言文字和图片等。来达到修改下拉刷新样式的目的。
using System;
using CoreAnimation;
using CoreGraphics;
using CrossUI.iOS.Dialog.Utilities;
using UIKit;
namespace RuilaiGrow.iOS
{
/// <summary>
/// 本项目的下啦刷新的view
/// by ge
/// </summary>
public class BabyRefreshHeadView : RefreshTableHeaderView
{
public BabyRefreshHeadView(CGRect rect) : base(rect)
{
//设置背景颜色
BackgroundColor = MvxTouchColor.ShallowGray;
}
//刷新下啦箭头
private static readonly UIImage arrow = UIImage.FromBundle("arrow" + ".png");
/// <summary>
/// 重写父类创建view的方法 并屏蔽父类view的创建
/// </summary>
public override void CreateViews()
{
//base.CreateViews();
//上次刷新时间文字
LastUpdateLabel = new UILabel
{
Font = UIFont.SystemFontOfSize(13f),
TextColor = new UIColor(0.47f, 0.50f, 0.57f, 1),
ShadowColor = UIColor.White,
ShadowOffset = new CGSize(0, 1),
BackgroundColor = MvxTouchColor.ShallowGray,
Opaque = true,
TextAlignment = UITextAlignment.Center,
AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin
};
AddSubview(LastUpdateLabel);
//刷新状态文字
StatusLabel = new UILabel
{
Font = UIFont.BoldSystemFontOfSize(14),
TextColor = new UIColor(0.47f, 0.50f, 0.57f, 1),
ShadowColor = LastUpdateLabel.ShadowColor,
ShadowOffset = new CGSize(0, 1),
BackgroundColor = MvxTouchColor.ShallowGray,
Opaque = true,
TextAlignment = UITextAlignment.Center,
AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin
};
AddSubview(StatusLabel);
SetStatus(RefreshViewStatus.PullToReload);
//右侧的image
ArrowView = new UIImageView
{
ContentMode = UIViewContentMode.ScaleAspectFill,
Image = arrow,
AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin
};
ArrowView.Layer.Transform = CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1);
AddSubview(ArrowView);
Activity = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.Gray)
{
HidesWhenStopped = true,
AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin
};
AddSubview(Activity);
}
private RefreshViewStatus status = (RefreshViewStatus)(-1);
/// <summary>
/// 重写父类状态的方法 并屏蔽父类的代码
/// 目的设置中文我们自己想要的文字
/// </summary>
/// <param name="status">Status.</param>
public override void SetStatus(RefreshViewStatus status)
{
//base.SetStatus(status);
if (this.status == status)
return;
string s = "松开刷新";
switch (status)
{
case RefreshViewStatus.Loading:
s = "加载中...";
break;
case RefreshViewStatus.PullToReload:
s = "下拉刷新...";
break;
}
StatusLabel.Text = s;
}
/// <summary>
/// 设置上次刷新时间的文字
/// 暂时没有用到
/// </summary>
private DateTime lastUpdateTime;
public DateTime LastUpdate
{
get { return lastUpdateTime; }
set
{
if (value == lastUpdateTime)
return;
lastUpdateTime = value;
if (value == DateTime.MinValue)
{
LastUpdateLabel.Text = "上次更新: 没有";
}
else
LastUpdateLabel.Text = String.Format("上次更新: {0:g}", value);
}
}
}
}
最后翻看他的源码,发现这个类中一些主要的方法可以复写,于是我决定复写他的方法修改样式。
首先ViewController要继承自DialogViewController,复写MakeRefreshTableHeaderView方法:
/// <summary>
/// 重写创建刷新view的方法
/// </summary>
/// <returns>The refresh table header view.</returns>
/// <param name="rect">Rect.</param>
public override RefreshTableHeaderView MakeRefreshTableHeaderView(CoreGraphics.CGRect rect)
{
var headView = new BabyRefreshHeadView(rect);
return headView;
}
其中BabyRefreshHeadView是继承自系统提供的RefreshTableHeaderView,代码在下面,下一步是在ViewController中指定刷新事件:
//刷新方法
RefreshRequested += delegate {
ViewModel.LoadLatestDataList();
};
在构造方法或者页面加载方法中都可以。
最后贴上继承自RefreshTableHeaderView的类,在其中自定义我们自己想要的语言文字和图片等。来达到修改下拉刷新样式的目的。
using System;
using CoreAnimation;
using CoreGraphics;
using CrossUI.iOS.Dialog.Utilities;
using UIKit;
namespace RuilaiGrow.iOS
{
/// <summary>
/// 本项目的下啦刷新的view
/// by ge
/// </summary>
public class BabyRefreshHeadView : RefreshTableHeaderView
{
public BabyRefreshHeadView(CGRect rect) : base(rect)
{
//设置背景颜色
BackgroundColor = MvxTouchColor.ShallowGray;
}
//刷新下啦箭头
private static readonly UIImage arrow = UIImage.FromBundle("arrow" + ".png");
/// <summary>
/// 重写父类创建view的方法 并屏蔽父类view的创建
/// </summary>
public override void CreateViews()
{
//base.CreateViews();
//上次刷新时间文字
LastUpdateLabel = new UILabel
{
Font = UIFont.SystemFontOfSize(13f),
TextColor = new UIColor(0.47f, 0.50f, 0.57f, 1),
ShadowColor = UIColor.White,
ShadowOffset = new CGSize(0, 1),
BackgroundColor = MvxTouchColor.ShallowGray,
Opaque = true,
TextAlignment = UITextAlignment.Center,
AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin
};
AddSubview(LastUpdateLabel);
//刷新状态文字
StatusLabel = new UILabel
{
Font = UIFont.BoldSystemFontOfSize(14),
TextColor = new UIColor(0.47f, 0.50f, 0.57f, 1),
ShadowColor = LastUpdateLabel.ShadowColor,
ShadowOffset = new CGSize(0, 1),
BackgroundColor = MvxTouchColor.ShallowGray,
Opaque = true,
TextAlignment = UITextAlignment.Center,
AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin
};
AddSubview(StatusLabel);
SetStatus(RefreshViewStatus.PullToReload);
//右侧的image
ArrowView = new UIImageView
{
ContentMode = UIViewContentMode.ScaleAspectFill,
Image = arrow,
AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin
};
ArrowView.Layer.Transform = CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1);
AddSubview(ArrowView);
Activity = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.Gray)
{
HidesWhenStopped = true,
AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin
};
AddSubview(Activity);
}
private RefreshViewStatus status = (RefreshViewStatus)(-1);
/// <summary>
/// 重写父类状态的方法 并屏蔽父类的代码
/// 目的设置中文我们自己想要的文字
/// </summary>
/// <param name="status">Status.</param>
public override void SetStatus(RefreshViewStatus status)
{
//base.SetStatus(status);
if (this.status == status)
return;
string s = "松开刷新";
switch (status)
{
case RefreshViewStatus.Loading:
s = "加载中...";
break;
case RefreshViewStatus.PullToReload:
s = "下拉刷新...";
break;
}
StatusLabel.Text = s;
}
/// <summary>
/// 设置上次刷新时间的文字
/// 暂时没有用到
/// </summary>
private DateTime lastUpdateTime;
public DateTime LastUpdate
{
get { return lastUpdateTime; }
set
{
if (value == lastUpdateTime)
return;
lastUpdateTime = value;
if (value == DateTime.MinValue)
{
LastUpdateLabel.Text = "上次更新: 没有";
}
else
LastUpdateLabel.Text = String.Format("上次更新: {0:g}", value);
}
}
}
}
相关文章推荐
- iOS 修改SearchBar的Textfiled的Cursor游标颜色和字体样式和大小;Disable输入框
- xamarin ios pullRefresh 下拉刷新,下拉加载更多
- iOS中默认样式修改
- xamarin.ios中设置button的边框及样式
- iOS修改导航栏返回按钮样式
- 【转】iOS导航栏样式修改
- xamarin.android pullToRefresharp.Android下拉刷新样式、侧滑删除功能
- CSS 修改 IOS 默认按钮样式
- iOS 硬件 大头针 - 高级 - 修改样式和移动
- Xamarin.iOS 自定义样式的弹出窗
- IOS开发 修改控制栏样式
- (原创)iOS 左滑删除,左滑时修改tableview中的样式
- iOS UITableView 修改 分区表头的样式和颜色
- iOS开发小技巧-修改SliderBar指针的样式(牢记这个方法,只能通过代码来修改)
- iOS小技巧 - 全局修改状态栏的样式为白色
- xamarin ios pullRefresh 下拉刷新,下拉加载更多
- iOS中修改状态栏StatusBar状态和样式的几种方法
- iOS开发之Swift标签栏按钮UITabBarItem样式修改(图标文字尺寸,颜色等)
- iOS中默认样式修改-b
- iOS 应用之间调用 出现在左上角的返回按钮怎么自定义 或者修改位置 样式