当前位置: 首页>>代码示例>>C#>>正文


C# NSRange类代码示例

本文整理汇总了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);
			}
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:29,代码来源:InteractiveTextColoringTextStorage.cs

示例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;
        }
开发者ID:yingfangdu,项目名称:BNR,代码行数:32,代码来源:ColorFormatter.cs

示例3: LowLevelSetAttributes

		public override void LowLevelSetAttributes (IntPtr attrs, NSRange range)
		{
			BeginEditing ();
			backingStore.LowLevelSetAttributes (attrs, range);
			Edited (NSTextStorageEditActions.Attributes, range, 0);
			EndEditing ();
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:7,代码来源:InteractiveTextColoringTextStorage.cs

示例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;
        }
开发者ID:afrog33k,项目名称:mcocoa,代码行数:28,代码来源:NSSpellChecker.cs

示例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;
        }
开发者ID:bholmes,项目名称:XamarinEvolve2013Project,代码行数:28,代码来源:PhoneNumberHelper.cs

示例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;
		}
开发者ID:tomgilder,项目名称:ReactiveTrader,代码行数:8,代码来源:NotionalTextFieldDelegate.cs

示例7: ShouldChangeText

		public override bool ShouldChangeText (UITextView textView, NSRange range, string text)
		{
			if (!text.Contains ("\n"))
				return true;

			textView.ResignFirstResponder ();
			return false;
		}
开发者ID:Clancey,项目名称:aws-sdk-net,代码行数:8,代码来源:SNSSampleViewController.cs

示例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 ();
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:8,代码来源:InteractiveTextColoringTextStorage.cs

示例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();
		}
开发者ID:ksasao,项目名称:Gochiusearch,代码行数:12,代码来源:MainWindowController.cs

示例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;
 }
开发者ID:sudipnath,项目名称:ios-sdk,代码行数:10,代码来源:ListViewSwipe.cs

示例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;
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:11,代码来源:BasicInteractionViewController.cs

示例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
 }
开发者ID:yudhitech,项目名称:xamarin-macios,代码行数:12,代码来源:iOSApiTypoTest.cs

示例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);
        }
开发者ID:patrykujawski,项目名称:MonoTouchMVVMCrossValidationTester,代码行数:13,代码来源:MyUIMoneyTextField.cs

示例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;
            }
开发者ID:rajeshwarn,项目名称:GhostPractice-iPadRepo,代码行数:13,代码来源:UIDecimalField.cs

示例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);
                }
            });
        }
开发者ID:flolovebit,项目名称:xamarin-evolve-2014,代码行数:53,代码来源:LongRunningTasksViewController.cs


注:本文中的NSRange类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。