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


C# NSString.Encode方法代码示例

本文整理汇总了C#中NSString.Encode方法的典型用法代码示例。如果您正苦于以下问题:C# NSString.Encode方法的具体用法?C# NSString.Encode怎么用?C# NSString.Encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NSString的用法示例。


在下文中一共展示了NSString.Encode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnElementPropertyChanged

		protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
		{
			if (e.PropertyName.Equals("Text") && Control != null)
			{
				// http://forums.xamarin.com/discussion/15530/nsattributedstringdocumentattributes-exception-on-ios-6

				NSParagraphStyle ps = NSParagraphStyle.Default;

				NSDictionary dict = new NSMutableDictionary() { {
						UIStringAttributeKey.Font,
						((ExtendedLabel)Element).Font.ToUIFont()
					},
				};

				var attr = new NSAttributedStringDocumentAttributes(dict);
				var nsError = new NSError();

				// This line announces, that content is html.
				attr.DocumentType = NSDocumentType.HTML;
				attr.StringEncoding = NSStringEncoding.UTF8;

				var html = ((ExtendedLabel)Element).TextExt + Environment.NewLine;

				NSString htmlString = new NSString(html); 
				NSData htmlData = htmlString.Encode(NSStringEncoding.UTF8); 

				NSAttributedString attrStr = new NSAttributedString(htmlData, attr, out dict, ref nsError);

				Control.AttributedText = attrStr;
				Control.SizeToFit();
				Control.SetNeedsLayout();

				Element.HeightRequest = Control.Bounds.Height;

				return;
			}

			if (e.PropertyName == "Height" || e.PropertyName == "Width")
			{
				// We calculate the correct height, because of the attributed string, Xamarin.Forms don't do it correct
				var width = (float)((ExtendedLabel)Element).Width;

				// Only do this, if we have a valid width
				if (width != -1)
				{
					var rect = Control.AttributedText.GetBoundingRect(new CoreGraphics.CGSize(width, float.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading, null);

					if (rect.Height != ((ExtendedLabel)Element).Height)
					{
						((ExtendedLabel)Element).HeightRequest = rect.Height;
					}
				}
			}

			base.OnElementPropertyChanged(sender, e);
		}
开发者ID:Surfoo,项目名称:WF.Player,代码行数:56,代码来源:ExtendedLabelRenderer.cs

示例2: WriteToFile

        public void WriteToFile(string filename, string text)
        {
            var textToWrite = new NSString(text);
            string path = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true)[0];
            path = string.Format("{0}/{1}", path, filename);
            NSError error = new NSError();

            if (NSFileManager.DefaultManager.FileExists(path))
            {
                NSFileManager.DefaultManager.Remove(path, out error);
            }

            NSFileManager.DefaultManager.CreateFile(path, new NSData(), NSFileAttributes.FromDictionary(new NSDictionary()));
            var data = textToWrite.Encode(NSStringEncoding.UTF8);
            data.Save(path, false);
        }
开发者ID:pgrzmil,项目名称:XamarinResearch,代码行数:16,代码来源:FileAccessTestService.cs

示例3: SummonThreeDSecure

		public static void SummonThreeDSecure (PaymentRequiresThreeDSecureModel threedDSecureReceipt, SecureWebView secureWebView)
		{
			secureWebView.ReceiptID =	threedDSecureReceipt.ReceiptId;

			NSCharacterSet allowedCharecterSet = NSCharacterSet.FromString (@":/=,!$&'()*+;[]@#?").InvertedSet;
			NSString paReq = new NSString (threedDSecureReceipt.PaReq);
			var encodedPaReq = paReq.CreateStringByAddingPercentEncoding (allowedCharecterSet);

			NSString termUrl = new NSString ("judo1234567890://threedsecurecallback");
			var encodedTermUrl = termUrl.CreateStringByAddingPercentEncoding (allowedCharecterSet);


			NSUrl url = new NSUrl (threedDSecureReceipt.AcsUrl);

			NSMutableUrlRequest req = new NSMutableUrlRequest (url);

			NSString postString = new NSString ("MD=" + threedDSecureReceipt.Md + "&PaReq=" + encodedPaReq + "&TermUrl=" + encodedTermUrl + "");
			NSData postData = postString.Encode (NSStringEncoding.UTF8);

			req.HttpMethod = "POST";
			req.Body = postData;

			try {
				DispatchQueue.MainQueue.DispatchAfter (DispatchTime.Now, () => {
					secureWebView.LoadRequest (req);

					JudoSDKManager.HideLoading ();
					secureWebView.Hidden = false;
				});
			} catch (Exception e) {
				if (secureWebView._failureCallback != null) {
					var judoError = new JudoError { Exception = e };
					secureWebView._failureCallback (judoError);
				}
			}
		}
开发者ID:TheJaniceTong,项目名称:Judo-Xamarin,代码行数:36,代码来源:JudoSDKManager.cs


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