I've been having difficulty with getting the images to show in ImageButton in Xamarin.Forms for my iOS application. The buttons are functional, and clickable, but the text and image source is not properly displaying. Instead, there is a clickable blue box, and ellipses as the text value. (http://i.imgur.com/kdQtOL0.png) I put the images in the Resources folder with the build action set to BundleResource. I can also display images as a simple image (rather than a button), so I know that iOS can see the images in the folder. I am using the following format to add buttons to my page.
Grid btns = SetUpGrid(1, 0, 0, 0, false);
var ib = new ImageButton();
ib.Image = "account.png";
ib.Text = "Account";
ib.HorizontalOptions = LayoutOptions.Start;
ib.VerticalOptions = LayoutOptions.FillAndExpand;
ib.Clicked += Home_BillClicked;
btns.Children.Add(ib, 0, 1);
Grid.SetColumnSpan(ib, 2);
The images appear and work perfectly in both the WP8 and Android apps. iOS seems to be the only one with an issue rendering the ImageButton. Does anyone know what may be causing the issue?
Instead ib.Image = "account.png", change to ib.Source = "account.png"; and add to your AppDelegate class inherits from XFormsApplicationDelegate.
Related
I'm very new to Xamarin.IOS. I'm using Rider as my IDE. I have a basic project set up, with a tableview. Each cell contains a button and a label. I can register the button press. What I want to do is change the icon of the button when I click on it. I can get the method to be called in C#, but I keep running into issues actually getting an image to load properly.
In Xcode, I created two image sets by dragging in two .png files into the Assets.xcassets.
I am loading my images like so:
UIImage checkedImage;
UIImage uncheckedImage;
public CampingListCell(IntPtr handle) : base(handle) {
checkedImage = UIImage.FromBundle ("checked");
uncheckedImage = UIImage.FromBundle("unchecked");
}
Then I swap images with
void AdjustImage() {
switch (listItem.CurrentCheckedState) {
case CheckedState.Checked:
ListItemCheckbox.ImageView.Image = checkedImage;
break;
case CheckedState.NotChecked:
ListItemCheckbox.ImageView.Image = uncheckedImage;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
However, when I run the program int he simulator, there's just a blank button. I have verified that the adjustImage method is being called properly on the click of the button.
I also tried ListItemCheckbox.SetImage(uncheckedImage, UIControlState.Normal);
Also, when I quit and reopen Xcode, the image sets are completely gone!
Am I missing something obvious? I am following the instructions at:
https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/images-icons/displaying-an-image?tabs=macos
If it matters I'm getting some lines in the console that I don't understand:
EDIT:
I just noticed that when creating the image sets, the rider console spits out these errors:
I have created a new issue for you in JetBrains issue tracker:
https://youtrack.jetbrains.com/issue/RIDER-57454
UPDATE: Will be fixed in Rider 2021.1
I wanted to make a kind of a notes app where users can add images inline with text, similar to how iOS' native Notes app does. Any advice on approaches I could take for this?
I'm new to iOS development and have been trying to teach myself a bunch of necessary skills and was curious as to how someone would go about doing this.
Thanks!
You can use UITextField to add images and text in one field, It can be done by using storyboard also and to do it programmatically is also convenient. Find the below code to add image programmatically in a text field :
var imageView = UIImageView()
var image = UIImage(named: "email.png")
imageView.image = image
emailField.leftView = imageView
emailField.leftViewMode = UITextFieldViewMode.always
emailField.leftViewMode = .always
UITextView is your best bet. It is not the most friendly UI component to work with if you are just starting out, but it is what Apple almost certainly uses for their Notes App, and supports inlining of text, images, hyperlinks, styles etc.
Issue Description
In my application I have a navigation bar search button set up as follows:
static navigatorButtons = {
leftButtons: [
{
id: 'back-nav-button',
icon: require('../assets/images/icons/arrow-left.png')
}
]
};
The button works as intended on both iOS and Android, but the button is blue on iOS. I understand that this is the desired behavior and that the color can be overridden by setting navBarButtonColor, but the problem is that it's a multi-colored button - meaning I want then button to simply contain the PNG image's colors, and not the navBarButtonColor.
I've tried setting navBarButtonColor to null, transparent, but nothing seems to work.
So my question is, is there a way to make navigation bar icons take on the color of the PNG provided, as is the case on Android?
Steps to Reproduce / Code Snippets / Screenshots
Simply run any RNN app on iOS with a simple static navigatorButtons = ... using a local multi-colored PNG and you'll see the colors of the icon get overwritten.
Environment
React Native Navigation version: 1.1.473
React Native version: 0.55.3
Platform(s) (iOS, Android, or both?): iOS
Device info (Simulator/Device? OS version? Debug/Release?): Android Emulator on Debug
On iOS, UIBarButtonItem uses images created with source image's alpha channel. To display the actual image (not an alpha channel mask of it) you need to change your image's rendering mode to alwaysOriginal
Although, looking at React Native Image class documentation I can't see renderingMode property
We've managed to find a workaround for this. By setting the disableIconTint button property to true, it disables the icon color override. See the following example:
static navigatorButtons = {
leftButtons: [
{
id: 'back-nav-button',
icon: require('../assets/images/icons/arrow-left.png'),
disableIconTint: true // Add this line to use the PNG's color
}
]
};
I'm attempting to use PDF files as icons in an app I'm working on. The issue I'm encountering is I'm getting inconsistent tint colors.
If I set a button image from interface builder, the icon image shows up black at runtime. Every time. Regardless of what I attempt to set from interface builder.
I tried setting my button icon image via code and instead of showing up black, it's white:
let myGraphicFile = UIImage(named: "myPDFImage")
let myButtonImage = myGraphicFile?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
myButton.setImage(myButtonImage, forState: .Normal)
From code, regardless of what I attempt to set the tint to, it's always white from code.
I discovered this post relating to Xcode 6.x, but I think it might be dated, as I'm able to partially do it, but I can't set the tint.
Use PDF in XCode for an AppIcon (.appiconset collection)
I create the icons in Inkscape, save as PDF 1.5. I add the file to Images.xcassets. In Images.xcassets' attributes inspector, I'm setting:
Devices to Universal
Scale factor to Single Vector.
Summary: I can get it to show up and scale properly, but it's either black from interface builder or white from code. I suspect I'm missing something re: how to save the file from Inkscape.
Thank you for reading. If you have any suggestions, I welcome them.
I have figured out how to create vector icons with Inkscape. When you use PDFs to display icons in iOS, you need to alter the Attributes Inspector for your icon in xcAssets as follows:
1) Drag the PDF into xcAssets
2) Set devices (I did Universal and it worked fine)
3) If your PDF icon is under 1x, 2x, or 3x size class, drag it to Universal and delete the rest of them.
4) Set Scale Factors to Single Vector.
5) Render as Template Image.
Once it's configured there, then you just treat it was you would any other image in interface builder. It's essentially the same thing I was doing in code, but I don't think it gets done in code...it's gotta be done on xcAssets where the image lives. It's my understanding iOS renders vector images for the size class at run time. I think by attempting to tweak it in code wasn't working because the image had already been rendered.
If anyone has any questions on this, I found this link helpful in resolving my issue.
Additionally, this post covers the topic, too. https://stackoverflow.com/a/25804358/4475605
So I have an annoying issue that I can't solve. I am creating an app in Flash Pro/AS3 for iOS. I have a button whose label font I want to change:
var ButtonTextFormat:TextFormat = new TextFormat("Showcard Gothic", 120);
//ButtonTextFormat.size = 120;
//ButtonTextFormat.font = "Showcard Gothic";
//ButtonTextFormat.embedFonts = true;
ButtonTextFormat.color = 0x00FF00;
//ButtonTextFormat.embedFonts = true;
SMButton.label = "PUSHME!";
SMButton.setStyle("textFormat", ButtonTextFormat);
I just used the standard button found in the Components Toolbox in Flash.
It displays correctly during debug, but once loaded into the iPhone, the label is changed to a default font.
I did embed the desired font through Text>Font Embedding... and it works for a text field that I have, but why not the button label?
I've tried ButtonTextFormat.embedFonts = true; but I get an error:
1119: Access of possibly undefined property embedFonts through a reference with static type flash.text:TextFormat.
Any help would be appreciated. Thanks.
embedFonts property is for TextField class, not for TextFormat class.
Follow this instructions to embed and use your embeded font properly Embedding Fonts for Components in Flash
I had the same problem recently. For components, you must set embedFonts with the .setStyle() method.
SMButton.setStyle("fontFamily", "Showcard Gothic");
SMButton.setStyle("embedFonts", true);
In the Flash IDE, you may need to add your font to the Library, and then export for ActionScript. The class name "TreasureMapDeadhand" for example.
Then in your document class:
import flash.text.Font;
Font.registerFont(TreasureMapDeadhand);
Another option if your linking your font multiple times, although not necessary, is store your font in a public var.
public var f:Font = new TreasureMapDeadhand();
SMButton.setStyle("fontFamily", f.fontName);
SMButton.setStyle("embedFonts", true);
Anyway, I hope this helps!