using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIKit;
using Foundation;
using Shared.IO;
using CoreGraphics;
namespace Shared
{
///
/// 文本输入框
///
public class TextView : View
{
///
/// 文字大小
///
/// The size of the text.
public float TextSize
{
get
{
return (float)uILable.TextSize.PointSize;
}
set
{
uILable.TextSize = UIFont.SystemFontOfSize(value);
}
}
int textID;
///
/// 根据ID获取对应的备注
///
public int TextID
{
get
{
return textID;
}
set
{
textID = value;
Text = Language.StringByID(TextID);
}
}
MyUILable uILable;
public TextView()
{
uiView = uILable = new MyUILable(this) { };
}
string text = "";
///
/// 文本
///
/// 文本
public string Text
{
get
{
return text;
}
set
{
text = value;
if(!IsCanRefresh){
return;
}
uILable.Text = value;
}
}
///
/// 文本颜色
///
public uint TextColor
{
get
{
nfloat r, g, b, a;
uILable.TextColor.GetRGBA(out r, out g, out b, out a);
r *= 255;
g *= 255;
b *= 255;
a *= 255;
return (uint)(r * 256 * 256 * 256 + g * 256 * 256 + b * 256 + a);
}
set
{
byte r, g, b, a;
r = (byte)(value / 256 / 256 % 256);
g = (byte)(value / 256 % 256);
b = (byte)(value % 256);
a = (byte)(value / 256 / 256 / 256 % 256);
uILable.TextColor = UIKit.UIColor.FromRGBA(r, g, b, a);
}
}
///
/// 是否支持换行
///
/// true if is more lines; otherwise, false.
public bool IsMoreLines
{
get
{
return uILable.IsMoreLines;
}
set
{
uILable.IsMoreLines = value;
}
}
public override void Refresh()
{
base.Refresh();
Text = Text;
}
}
class MyUILable : UILabel
{
[Weak] TextView textView;
public MyUILable(TextView textView)
{
this.textView = textView;
LineBreakMode = UILineBreakMode.MiddleTruncation;
TextAlignment = UITextAlignment.Center;
}
bool isMoreLines;
public bool IsMoreLines
{
get
{
return isMoreLines;
}
set
{
isMoreLines = value;
if (isMoreLines)
{
Lines = 0;
}
else
{
Lines = 1;
}
}
}
///
/// 点击开始
///
/// Touches.
/// Evt.
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
textView?.TouchEvent(EventActions.Down, (touches.AnyObject as UITouch).LocationInView(this));
}
///
/// 移动
///
/// Touches.
/// Evt.
public override void TouchesMoved(NSSet touches, UIEvent evt)
{
textView?.TouchEvent(EventActions.Move, (touches.AnyObject as UITouch).LocationInView(this));
}
///
/// 点击弹起
///
/// Touches.
/// Evt.
public override void TouchesEnded(NSSet touches, UIEvent evt)
{
textView?.TouchEvent(EventActions.Up, (touches.AnyObject as UITouch).LocationInView(this));
}
public override void TouchesCancelled(NSSet touches, UIEvent evt)
{
textView?.TouchEvent(EventActions.Cancel, (touches.AnyObject as UITouch).LocationInView(this));
}
///
/// 因为这个视图很奇怪,会自动加了两个UIImageView,所以这个特殊处理一下
///
/// View.
public override void AddSubview(UIView view)
{
if (view.GetType() == typeof(UIImageView) && view.Tag != int.MinValue)
{
return;
}
base.AddSubview(view);
}
///
/// 文本
///
/// The text.
public string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
}
}
///
/// 文本的颜色
///
/// 文本的颜色
public UIColor TextColor
{
get
{
return base.TextColor;
}
set
{
base.TextColor = value;
}
}
///
/// 文本的大小
///
/// 文本的大小
public UIFont TextSize
{
get
{
return base.Font;
}
set
{
base.Font = value;
}
}
}
//class MyUILable : UIScrollView
//{
// View view;
// public MyUILable(View view)
// {
// this.view = view;
// commonInit();
// }
// ///
// /// 点击开始
// ///
// /// Touches.
// /// Evt.
// public override void TouchesBegan(NSSet touches, UIEvent evt)
// {
// //base.TouchesBegan(touches, evt);
// view.TouchEvent(EventActions.Down, (touches.AnyObject as UITouch).LocationInView(this));
// }
// ///
// /// 移动
// ///
// /// Touches.
// /// Evt.
// public override void TouchesMoved(NSSet touches, UIEvent evt)
// {
// //base.TouchesMoved(touches, evt);
// view.TouchEvent(EventActions.Move, (touches.AnyObject as UITouch).LocationInView(this));
// }
// ///
// /// 点击弹起
// ///
// /// Touches.
// /// Evt.
// public override void TouchesEnded(NSSet touches, UIEvent evt)
// {
// //base.TouchesEnded(touches, evt);
// view.TouchEvent(EventActions.Up, (touches.AnyObject as UITouch).LocationInView(this));
// }
// ///
// /// 因为这个视图很奇怪,会自动加了两个UIImageView,所以这个特殊处理一下
// ///
// /// View.
// public override void AddSubview(UIView view)
// {
// if (view.GetType() == typeof(UIImageView) && view.Tag != int.MinValue)
// {
// return;
// }
// base.AddSubview(view);
// }
// UILabel[] labels = new UILabel[2];
// float scrollSpeed = 30;
// float bufferSpaceBetweenLabels = 20;
// void commonInit()
// {
// for (int i = 0; i < labels.Length; ++i)
// {
// labels[i] = new UILabel();
// labels[i].TextColor = UIColor.White;
// labels[i].BackgroundColor = UIColor.Clear;
// labels[i].Text = " ";
// AddSubview(labels[i]);
// }
// ShowsVerticalScrollIndicator = false;
// ShowsHorizontalScrollIndicator = false;
// UserInteractionEnabled = false;
// }
// void scroll()
// {
// ContentOffset = new CGPoint(0, 0);
// AnimateNotify(
// labels[0].Frame.Size.Width / scrollSpeed,
// 0f,
// UIViewAnimationOptions.CurveLinear, () =>
// {
// ContentOffset = new CGPoint(labels[0].Frame.Width + bufferSpaceBetweenLabels, 0);
// },
// finished =>
// {
// if (finished)
// scroll();
// }
// );
// }
// void readjustLabels()
// {
// Layer.RemoveAllAnimations();
// float offset = 0.0f;
// for (int i = 0; i < labels.Length; ++i)
// {
// labels[i].SizeToFit();
// CGPoint center;
// center = labels[i].Center;
// center.Y = Center.Y - Frame.Y;
// labels[i].Center = center;
// CGRect frame;
// frame = labels[i].Frame;
// frame.X = offset;
// labels[i].Frame = frame;
// offset += (float)labels[i].Frame.Width + bufferSpaceBetweenLabels;
// }
// var size = new CGSize
// {
// Width = labels[0].Frame.Width + Frame.Width + bufferSpaceBetweenLabels,
// Height = Frame.Height
// };
// ContentSize = size;
// SetContentOffset(new CGPoint(0, 0), false);
// if (labels[0].Frame.Width > Frame.Width)
// {
// for (int i = 1; i < labels.Length; ++i)
// {
// labels[i].Hidden = false;
// }
// scroll();
// }
// else
// {
// for (int i = 1; i < labels.Length; ++i)
// {
// labels[i].Hidden = true;
// }
// CGPoint center;
// center = labels[0].Center;
// center.X = Center.X - Frame.X;
// labels[0].Center = center;
// }
// }
// ///
// /// 文本
// ///
// /// The text.
// public string Text
// {
// get
// {
// return labels[0].Text;
// }
// set
// {
// if (labels[0].Text == value)
// {
// return;
// }
// for (int i = 0; i < labels.Length; ++i)
// {
// labels[i].Text = value;
// }
// readjustLabels();
// }
// }
// ///
// /// 文本的颜色
// ///
// /// 文本的颜色
// public UIColor TextColor
// {
// get
// {
// return labels[0].TextColor;
// }
// set
// {
// for (int i = 0; i < labels.Length; ++i)
// {
// labels[i].TextColor = value;
// }
// }
// }
// ///
// /// 文本的大小
// ///
// /// 文本的大小
// public UIFont TextSize
// {
// get
// {
// return labels[0].Font;
// }
// set
// {
// for (int i = 0; i < labels.Length; ++i)
// {
// labels[i].Font = value;
// }
// }
// }
//}
}