本文整理汇总了C#中NSRange类的典型用法代码示例。如果您正苦于以下问题:C# NSRange类的具体用法?C# NSRange怎么用?C# NSRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NSRange类属于命名空间,在下文中一共展示了NSRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyTokenAttributes
void ApplyTokenAttributes (NSRange searchRange)
{
NSDictionary attributesForToken = Tokens ["DefaultTokenName"];
int startPos = (int)searchRange.Location;
string text = backingStore.Value.Substring ((int)searchRange.Location,(int)searchRange.Length);
int nextSpace = text.IndexOfAny (" \n\t.".ToCharArray ());
int lastPos = 0;
string token;
NSRange tokenRange;
while (true) {
if (nextSpace == -1)
nextSpace = text.Length;
token = text.Substring (lastPos, nextSpace - lastPos);
tokenRange = new NSRange (lastPos + startPos, nextSpace - lastPos);
if (Tokens.ContainsKey (token))
attributesForToken = Tokens [token];
else
attributesForToken = Tokens ["DefaultTokenName"];
AddAttributes (attributesForToken, tokenRange);
if (nextSpace == text.Length)
break;
lastPos = nextSpace + 1;
nextSpace = text.IndexOfAny (" \n\t.".ToCharArray (), nextSpace + 1);
}
}
示例2: IsPartialStringValid
public bool IsPartialStringValid(ref NSString partial, ref NSRange selPtr, NSString origString, ref NSRange origSel, IntPtr error)
{
// Zero length strings are OK
if (partial.Length == 0) {
return true;
}
string match = FirstColorKeyForPartialString(partial);
// No color match?
if (match == null) {
return false;
}
// If no letters were added, it is a delete
// Console.WriteLine("orig string: {0}, partial string: {1}", origString, partial);
if (oldColorStringLength == partial.Length) {
oldColorStringLength--;
selPtr.Location = partial.Length -1;
selPtr.Length = match.Length - selPtr.Location;
partial = (NSString)match;
return false;
}
oldColorStringLength = partial.Length;
// If the partial string is shorter than the match,
// provide the match and set the selection
if (match.Length != partial.Length) {
selPtr.Location = partial.Length;
selPtr.Length = match.Length - selPtr.Location;
partial = (NSString)match;
return false;
}
return true;
}
示例3: LowLevelSetAttributes
public override void LowLevelSetAttributes (IntPtr attrs, NSRange range)
{
BeginEditing ();
backingStore.LowLevelSetAttributes (attrs, range);
Edited (NSTextStorageEditActions.Attributes, range, 0);
EndEditing ();
}
示例4: requestCheckingOfString_range_types_options_inSpellDocumentWithTag_completionHandler
/// <exclude/>
public int requestCheckingOfString_range_types_options_inSpellDocumentWithTag_completionHandler(
NSString stringToCheck,
NSRange range,
ulong checkingTypes,
NSDictionary options,
int tag,
Action<int, NSArray, NSOrthography, int> callback)
{
RequestCheckingCallback thunk = (IntPtr context, int sequenceNumber, IntPtr resultsPtr, IntPtr orthographyPtr, int wordCount) =>
{
var results = NSObject.Lookup(resultsPtr).To<NSArray>();
var orthography = NSObject.Lookup(orthographyPtr).To<NSOrthography>();
callback(sequenceNumber, results, orthography, wordCount);
};
var block = new ExtendedBlock(thunk);
int result = Call("requestCheckingOfString:range:types:options:inSpellDocumentWithTag:completionHandler:",
stringToCheck,
range,
checkingTypes,
options,
tag,
block).To<int>();
GC.KeepAlive(block);
return result;
}
示例5: ShoudChange
public static bool ShoudChange(UITextField textField, NSRange range, string toString)
{
int length = getLength (textField.Text);
if(length == 10)
{
if(range.Length == 0)
return false;
}
if(length == 3)
{
string num = formatNumber(textField.Text);
textField.Text = string.Format ("({0}) ", num);
if(range.Length > 0)
textField.Text = string.Format ("{0}", num.Substring(0, 3));
}
else if(length == 6)
{
string num = formatNumber(textField.Text);
textField.Text = string.Format ("({0}) {1}-",num.Substring (0, 3) ,num.Substring (3));
if(range.Length > 0)
textField.Text = string.Format ("({0}) {1}",num.Substring (0, 3) ,num.Substring (3));
}
return true;
}
示例6: ShouldChangeCharacters
public override bool ShouldChangeCharacters(UITextField textField, NSRange theRange, String replacementString)
{
System.Console.WriteLine ("ShouldChangeCharacters '{0}' -> {1}, {2}, '{3}' ?", textField.Text, theRange.Location, theRange.Length, replacementString);
// We could prevent (or warn of) nonsensical or out-of-bounds values?
return true;
}
示例7: ShouldChangeText
public override bool ShouldChangeText (UITextView textView, NSRange range, string text)
{
if (!text.Contains ("\n"))
return true;
textView.ResignFirstResponder ();
return false;
}
示例8: Replace
public override void Replace (NSRange range, string newValue)
{
BeginEditing ();
backingStore.Replace (range, newValue);
Edited (NSTextStorageEditActions.Characters | NSTextStorageEditActions.Attributes, range, newValue.Length - range.Length);
dynamicTextNeedsUpdate = true;
EndEditing ();
}
示例9: ClearLog
/// <summary>
/// Clears the present logs.
/// </summary>
private void ClearLog()
{
var stor = LogField.TextStorage;
var wholeRange = new NSRange(0, stor.Length);
stor.BeginEditing();
stor.DeleteRange(wholeRange);
stor.EndEditing();
}
示例10: AttributedMailText
public NSAttributedString AttributedMailText(string text)
{
Random r = new Random ();
string randomString = loremIpsum.GenerateString (10 + r.Next (0, 16));
string str = String.Format ("{0}\n{1}", text, randomString);
NSMutableAttributedString attrStr = new NSMutableAttributedString (str, new NSDictionary ());
NSRange range = new NSRange (str.IndexOf ("\n"), "\n".Length);
attrStr.AddAttribute(UIStringAttributeKey.ForegroundColor, UIColor.Gray, new NSRange(range.Location, str.Length - range.Location));
return attrStr;
}
示例11: ShouldInteractWithUrl
bool ShouldInteractWithUrl (UITextView textView, NSUrl url, NSRange characterRange)
{
if (url.Host == "www.xamarin.com") {
var webViewController = (WebViewController)Storyboard.InstantiateViewController ("WebViewController");
PresentViewController (webViewController, true, delegate {
webViewController.webView.LoadRequest (NSUrlRequest.FromUrl (url));
});
return false;
};
return true;
}
示例12: GetTypo
public override string GetTypo(string txt)
{
#if __WATCHOS__
return string.Empty;
#else
var checkRange = new NSRange (0, txt.Length);
var typoRange = checker.RangeOfMisspelledWordInString (txt, checkRange, checkRange.Location, false, "en_US");
if (typoRange.Length == 0)
return String.Empty;
return txt.Substring ((int) typoRange.Location, (int) typoRange.Length);
#endif
}
示例13: ShouldChangeCharacters
public override bool ShouldChangeCharacters(UITextField textField, NSRange range, string replacementString)
{
if (string.IsNullOrEmpty(replacementString))
return true;
var newText = (textField.Text ?? "").Remove(range.Location, range.Length)
.Insert(range.Location, replacementString);
//MvxTrace.Trace(
// "ShouldChangeCharacters, before: {0}, replace: {1}, newtext: {2}",
// this.Text, replacementString, newText);
return IsOk(newText);
}
示例14: ShouldChangeCharacters
public override bool ShouldChangeCharacters(UITextField textField, NSRange range, string replacementString)
{
var newText = textField.Text.Remove (range.Location, range.Length);
newText = newText.Insert (range.Location, replacementString);
if (newText.Length > 0) {
textField.Text = (UIDecimalField.GetAmountFromString (newText)).ToString ("N2");
return false;
}
return false;
}
示例15: HandleCalculatePi
/// <summary>
/// Gets called when pressing the button to calculate PI.
/// </summary>
/// <param name="sender">Sender.</param>
partial void HandleCalculatePi(UIButton sender)
{
this.isCalculating = !this.isCalculating;
btnCalculate.SetTitle(this.isCalculating ? "Stop calculating" : "Start calculating", UIControlState.Normal);
if(!this.isCalculating)
{
// Cancel calculation if it is currently running.
this.cts.Cancel();
return;
}
else
{
// Use a cancellation token to be able to stop the calculation.
this.cts = new CancellationTokenSource();
this.txtPi.Text = string.Empty;
}
// Prepare for background processing.
int taskId = -1;
// We are running on an extra thread here. Still, the app gets paused if it is backgrounded.
Task.Run(() =>
{
// TODO: LongRunningTasks 01 - Comment back in to prevent thread from being interrupted if home button is pressed
// taskId = UIApplication.SharedApplication.BeginBackgroundTask(() => {
// Console.WriteLine("Background time expires!");
// this.cts.Cancel();
// });
Helpers.CalcPi(pi =>
{
Console.WriteLine("Background time remaining: " + Math.Round(UIApplication.SharedApplication.BackgroundTimeRemaining) + " seconds");
Console.WriteLine("A bit of Pi: " + pi);
this.InvokeOnMainThread(() =>
{
this.txtPi.Text += " " + pi;
var range = new NSRange(txtPi.Text.Length - 1, 1);
txtPi.ScrollRangeToVisible(range);
});
}, this.cts.Token);
if(taskId != -1)
{
// Balanced call to BeginBackgroundTask()
UIApplication.SharedApplication.EndBackgroundTask(taskId);
}
});
}