मेरे पास एमवीएमआरक्रॉस के साथ एक एक्समरिन प्रोजेक्ट है। वहाँ उप हैं:एक्समारिन: आईओएस लाइब्रेरी प्रोजेक्ट से छवि लोड करने के लिए कैसे करें
- कोर (PCL)
- ViewModel (PCL)
- आईओएस (निष्पादन)
मैं अपने आईओएस परियोजना (Resoureces/images/test_image के लिए एक छवि जोड़ें। png), तो मैं इसे इस कोड के साथ लोड कर सकते हैं:
UIImage image = UIImage.FromBundle("Images/test_icon.png");
अब, मैं एक नया subproject उपयोग करना चाहते हैं
- नियंत्रण (आईओएस लाइब्रेरी)
यह पुस्तकालय एक छवि लोड करना चाहिए। मैंने नियंत्रण (Resoureces/images/test_image.png) पर एक छवि जोड़ा
लेकिन मैं इस छवि को नियंत्रण प्रोजेक्ट में लोड नहीं कर सकता।
मेरा प्रश्न: आईओएस पुस्तकालयों से छवियों को कैसे लोड करें?
public class MyButton : UIButton
{
public MyButton() : base()
{
Initialize();
}
void Initialize()
{
// load image from bundle
UIImage image = UIImage.FromBundle("Images/test_icon.png");
// image is null
this.SetImage (image, UIControlState.Normal);
}
}
और ViewController वर्ग है:
public partial class FirstView : MvxViewController
{
public FirstView() : base ("FirstView", null)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// load image from bundle
// UIImage image = UIImage.FromBundle("Images/test_icon.png");
// image is not null if added in iOS Proj
// this.imageView.Image = image;
MyButton button = new MyButton();
View.Add (button);
View.AddConstraint (NSLayoutConstraint.Create (button, NSLayoutAttribute.Right, NSLayoutRelation.Equal, View, NSLayoutAttribute.Right, 1, 10));
View.AddConstraint (NSLayoutConstraint.Create (button, NSLayoutAttribute.Top, NSLayoutRelation.Equal, View, NSLayoutAttribute.Top, 1, 74));
View.AddConstraint (NSLayoutConstraint.Create (button, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 0, 64));
View.AddConstraint (NSLayoutConstraint.Create (button, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 0, 64));
}
}
यहाँ पूर्ण proj है: https://bitbucket.org/ww_wschaefer/xamarin-first-crossover-app/overview
आप नहीं कर सकते जब तक कि इसकी उपलब्ध bundeled संसाधन के रूप में बंडल से उपयोग करते हैं, मुझे लगता है कि आप 'UIImage.FromFile (" छवियाँ/test_icon.png "का उपयोग करने का बेहतर होगा) '। आपको यह भी देखना चाहिए [प्रश्न] (http://stackoverflow.com/q/18130779/1155650)। –
मैं विश्वास नहीं कर सकता, समाधान इतना आसान है, रोहित धन्यवाद। – iOSfleer
खुश आपकी समस्या हल हो गई थी। यदि आप रुचि रखते हैं तो मैंने स्पष्टीकरण जोड़ा है। –