| | |
| | | /// </summary>
|
| | | private NormalViewControl btnLineTemp = null;
|
| | | /// <summary>
|
| | | /// 联动底线(值输入之后,线的颜色会变)
|
| | | /// 联动底线(光标进来之后,线的颜色会变)
|
| | | /// </summary>
|
| | | public NormalViewControl btnLine
|
| | | {
|
| | |
| | | this.btnLineTemp = value;
|
| | | }
|
| | | }
|
| | | /// <summary>
|
| | | /// 联动外框
|
| | | /// </summary>
|
| | | private NormalFrameLayout frameBorder = null;
|
| | | /// <summary>
|
| | | /// 联动外框(光标进来之后,外框的颜色会变)
|
| | | /// </summary>
|
| | | public NormalFrameLayout FrameBorder
|
| | | {
|
| | | set
|
| | | {
|
| | | this.frameBorder = value;
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 输入结束的事件
|
| | | /// </summary>
|
| | | public Action FinishInputEvent = null;
|
| | | /// <summary>
|
| | | /// 最大输入长度(目前只针对按下回车键时进行检测,超过时,不会调用FinishInputEvent)
|
| | | /// 值改变事件(受MaxByte属性限制)
|
| | | /// </summary>
|
| | | public int MaxByte = 0;
|
| | | public Action<string> TextChangedEvent = null;
|
| | | /// <summary>
|
| | | /// 指定该输入框是否为不可省略(默认为false)
|
| | | /// </summary>
|
| | | public bool MustInput = false;
|
| | |
|
| | | private int m_MaxByte = -1;
|
| | | /// <summary>
|
| | | /// 最大输入Byte长度
|
| | | /// </summary>
|
| | | public int MaxByte
|
| | | {
|
| | | get { return m_MaxByte; }
|
| | | set
|
| | | {
|
| | | m_MaxByte = value;
|
| | | this.TextChangeEventHandler -= this.TxtCode_TextChangedEvent;
|
| | | if (m_MaxByte > 0)
|
| | | {
|
| | | this.TextChangeEventHandler += this.TxtCode_TextChangedEvent;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private bool m_UseFocusColor = false;
|
| | | /// <summary>
|
| | |
| | | {
|
| | | btnLineTemp.BackgroundColor = UserCenterColor.Current.ButtomLine;
|
| | | }
|
| | | if (frameBorder != null)
|
| | | {
|
| | | frameBorder.BorderColor = 0xffcccccc;
|
| | | }
|
| | | if (m_UseFocusColor == true)
|
| | | {
|
| | | //灰色字体
|
| | |
| | | if (btnLineTemp != null)
|
| | | {
|
| | | btnLineTemp.BackgroundColor = UserCenterColor.Current.TextFrameSelectColor;
|
| | | }
|
| | | if (frameBorder != null)
|
| | | {
|
| | | frameBorder.BorderColor = UserCenterColor.Current.TextFrameSelectColor;
|
| | | }
|
| | | if (m_UseFocusColor == true)
|
| | | {
|
| | |
| | | return;
|
| | | }
|
| | | this.FinishInputEvent?.Invoke();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 值改变事件
|
| | | /// </summary>
|
| | | /// <param name="sender"></param>
|
| | | /// <param name="value"></param>
|
| | | private void TxtCode_TextChangedEvent(object sender, string value)
|
| | | {
|
| | | var byteData = Encoding.UTF8.GetBytes(value);
|
| | | var newValue = value;
|
| | |
|
| | | //如果输入的值,已经大于指定的byte数,则截取
|
| | | if (byteData.Length > this.m_MaxByte)
|
| | | {
|
| | | //截取指定的byte字节
|
| | | newValue = Encoding.UTF8.GetString(byteData, 0, this.m_MaxByte);
|
| | | //最后一位不要,因为截取的最后一位可能是乱码
|
| | | newValue = newValue.Substring(0, newValue.Length - 1);
|
| | | //拼接上它的下一位,然后检测
|
| | | var checkValue = newValue + value[newValue.Length];
|
| | | if (Encoding.UTF8.GetBytes(checkValue).Length <= this.m_MaxByte)
|
| | | {
|
| | | //正好匹配byte数
|
| | | newValue = checkValue;
|
| | | }
|
| | | this.Text = newValue;
|
| | | //将光标至于最后
|
| | | #if Android
|
| | | this.SetSelectionEnd();
|
| | | #endif
|
| | | }
|
| | | this.TextChangedEvent?.Invoke(newValue);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <returns></returns>
|
| | | private string CheckMaxByte()
|
| | | {
|
| | | if (this.MaxByte != 0)
|
| | | {
|
| | | if (Encoding.UTF8.GetBytes(this.Text.Trim()).Length > this.MaxByte)
|
| | | {
|
| | | //输入内容过长,最大{0}字节
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uInputContentIsOverLengthMsg);
|
| | | msg.Replace("{0}", this.MaxByte.ToString());
|
| | |
|
| | | return msg;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 一般方法___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// Y轴重置(真实数值,没有父容器无效)
|
| | | /// </summary>
|
| | | /// <param name="alignment">上下对齐方式</param>
|
| | | /// <param name="Space">上下两部分的间距</param>
|
| | | public void ReSetYaxis(UViewAlignment alignment, int Space = 0)
|
| | | {
|
| | | if (this.Parent == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //Y轴重置
|
| | | this.Y = HdlControlLogic.Current.GetControlChidrenYaxis(this.Parent.Height, this.Height, alignment, Space);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 计算图片的真实高宽度
|
| | |
| | | public override void RemoveFromParent()
|
| | | {
|
| | | this.FinishInputEvent = null;
|
| | | this.TextChangedEvent = null;
|
| | | if (this.Parent != null)
|
| | | {
|
| | | base.RemoveFromParent();
|