ADuggan
ADuggan

Reputation: 501

Xamarin iOS UIButton image not showing on device when testing

I am currently testing my xamarin iOS app on TestFlight with an iOS device. The app is running fine but the images in my UIButtons arent showing up at all.

Heres my button code:

    _uiAttributes.myScheduleImage = UIImage.FromFile("images/myschedule.PNG");
                _uiAttributes.myCareersImage = UIImage.FromFile("images/mycareer.PNG");
                _uiAttributes.mySocialImage = UIImage.FromFile("images/mysocial.PNG");
                _uiAttributes.FeedbackImage = UIImage.FromFile("images/feedback.PNG");
                _uiAttributes.myDetailsImage = UIImage.FromFile("images/mydetails.PNG");

buttonList = new List<UIButton>
            {
                _uiControls.btn_MySchedule,
                _uiControls.btn_MyCareer,
                _uiControls.btn_MySocial,
                _uiControls.btn_Feedback,
                _uiControls.btn_MyDetails
            };

buttonImageList = new List<UIImage>
            {
                _uiAttributes.myScheduleImage,
                _uiAttributes.myCareersImage,
                _uiAttributes.mySocialImage,
                _uiAttributes.feedbackImage,
                _uiAttributes.myDetailsImage
            };

I pass this code through to a Draw method.

public void DrawImageButton(List<UIButton> buttonList, List<CGRect> buttonDimensionsList, List<UIImage> buttonImageList, UIView container)
        {
            for(int i = 0; i < buttonList.Count; i++)
            {
                buttonList[i].Frame = buttonDimensionsList[i];
                buttonList[i].SetImage(buttonImageList[i], UIControlState.Normal);

                container.AutoresizingMask = UIViewAutoresizing.FlexibleMargins;
                buttonList[i].AutoresizingMask = UIViewAutoresizing.FlexibleWidth;

                container.AddSubview(buttonList[i]);
            }
        }

The buttons are showing up when i run it on a simulator but not my actual device.

I will attach an screenshot of my images below: Resources/images

I have checked a number of related answers but theyre all in Xcode. I am currently using Visual Studio 2015 to develop my application.

If anyone can help or point me in the right direction that would be great.

Upvotes: 1

Views: 877

Answers (1)

ADuggan
ADuggan

Reputation: 501

So I have managed to fix this issue. The problem was that i never changed the Copy to Output Directory to "Copy Always" in the properties panel for each image. Also I had to state the path of the image being loaded.

_uiAttributes.myScheduleImage = UIImage.FromFile("images/myschedule.PNG");

Thanks for all the help!

Upvotes: 1

Related Questions