Visual Studio for Mac for iOS 画像読み込みネタ
Visual Studio for MacのiOSアプリ作成で
ネット上の画像読み込みの方法がなかったので
とりあえずコードだけ貼っておきます
修正、全体像を把握しやすいように
usingから書いてないサイトが多くて、どこにあるのかよくわからないパターンも多いと思うので
using System;
using System.Net;
using System.IO;
using UIKit;
using Foundation;
namespace Test
{
public partial class ViewController : UIViewController
{
partial void img_TouchUpInside(UIButton sender)
{
string url = "http://www.hoge.com/hoge.jpg";
image.Image = LoadImage(url);
}
public UIImage LoadImage(string path){
WebClient webClient = new WebClient();
byte[] pic = webClient.DownloadData(path);
return UIImage.LoadFromData(NSData.FromArray(pic));
}
}
}
