本文整理汇总了C#中UITextView.GetOffsetFromPosition方法的典型用法代码示例。如果您正苦于以下问题:C# UITextView.GetOffsetFromPosition方法的具体用法?C# UITextView.GetOffsetFromPosition怎么用?C# UITextView.GetOffsetFromPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UITextView
的用法示例。
在下文中一共展示了UITextView.GetOffsetFromPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Changed
async public override void Changed (UITextView textView)
{
string text = StringUtils.TrimWhiteSpaceAndNewLine (textView.Text);
UpdateCharacterCount(text);
Validate ();
if (SuggestionsCollectionView != null) {
if (text.Length <= 2 || !text.Contains ("@")) {
SuggestionsCollectionView.Hidden = true;
return;
}
int cursorPositionEarly = (int)textView.GetOffsetFromPosition (textView.BeginningOfDocument, textView.SelectedTextRange.Start);
if (cursorPositionEarly <= 0)
{
return;
}
string charToTest = textView.Text.Substring (cursorPositionEarly - 1, 1);
if (charToTest != "@" && charToTest != " ") {
string beforeTextEarly = textView.Text.Substring (0, cursorPositionEarly);
string strippedToLastSpaceOnward = beforeTextEarly;
if (strippedToLastSpaceOnward.IndexOf ("") > -1 && strippedToLastSpaceOnward.Length > 2) {
strippedToLastSpaceOnward = strippedToLastSpaceOnward.Substring (strippedToLastSpaceOnward.LastIndexOf (" ") + 1);
}
if (strippedToLastSpaceOnward.Length > 1 && strippedToLastSpaceOnward.Substring (0, 1) == "@") {
try
{
List<User> users = await TenServices.SearchFollowingUsers(strippedToLastSpaceOnward.Substring(1));
SuggestionsCollectionViewDelegate del = new SuggestionsCollectionViewDelegate();
del.ItemSelectedAction += delegate (int index)
{
int cursorPosition = (int)textView.GetOffsetFromPosition(textView.BeginningOfDocument, textView.SelectedTextRange.Start);
string currentText = textView.Text;
string beforeText = currentText.Substring(0, cursorPosition);
beforeText = beforeText.Substring(0, beforeText.LastIndexOf('@'));
string afterText = currentText.Substring(cursorPosition);
currentText = currentText.Substring(0, cursorPosition);
textView.Text = beforeText + "@" + users[index].username + " " + afterText;
SuggestionsCollectionView.Hidden = true;
UpdateCharacterCount(textView.Text);
};
SuggestionsCollectionView.Delegate = del;
SuggestionsCollectionView.DataSource = new SuggestionsCollectionViewDataSource(users);
SuggestionsCollectionView.Hidden = false;
}
catch (RESTError e)
{
Console.WriteLine(e.Message);
}
finally
{
UpdateCharacterCount(text);
}
} else {
SuggestionsCollectionView.Hidden = true;
}
}
UpdateCharacterCount(text);
}
}