Setting the navigation bar color in monotouch - xamarin.ios

I am attempting to write an application with MonoTouch. I need to set the background color of the navigation bar. I'd like to set it to orange. This seems like an easy task, but I can't seem to get it to work. Currently, I'm doing the following in the AppDelegate.cs file:
this.window = new UIWindow (UIScreen.MainScreen.Bounds);
this.rootNavigationController = new UINavigationController();
UIColor backgroundColor = new UIColor(74, 151, 223, 255);
this.rootNavigationController.NavigationBar.BackgroundColor = UIColor.Orange;
However, the navigation bar color is still the default color. How do I set the background color of the navigation bar?

You can do this on an ad-hoc basis as Rob described using the TintColor property:
this.rootNavigationController.NavigationBar.TintColor = UIColor.Orange;
Alternatively, you can also set the TintColor for all UINavigationBars at once using the UIAppearance proxy in iOS 5. This is usually done somewhere near DidFinishLaunchingWithOptions method in the AppDelegate:
UINavigationBar.Appearance.TintColor = UIColor.Orange;
You can check out the Apple doc for more detailed information and implementation restrictions:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html

Try changing the TintColor and Translucent properties.

Related

navigation background image xamarin ios

I'm new in xamarin(start using 2 week), now I need do a background Image wtih navigation bar like below picture? how can I do it?
You need to add an UIImage in your UIViewController (filling whole or only top of ViewController) setting your UINavigationBar to a clear color with
YourNavigationBar.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
YourNavigationBar.ShadowImage = new UIImage();
YourNavigationBar.Translucent = true;
YourNavigationBar.BackgroundColor = UIColor.Clear;
To reset UINavigationBar transparency you have to use:
YourNavigationBar.SetBackgroundImage(null, UIBarMetrics.Default);

Is it possible to change inactive TabBarIOS Icon color in React Native?

As in subject, I am wondering if right now in React Native is an option to change color of inactive TabBar icon from default gray to custom color? With or without using react-native-vector-icons
I found solution, but your icon should be in "inactive" color. To achieve this go to RTCTabBarItem.m and change first line in method setIcon:
- (void)setIcon:(UIImage *)icon
{
_icon = [icon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
if (_icon && _systemIcon != NSNotFound) {
_systemIcon = NSNotFound;
UITabBarItem *oldItem = _barItem;
_barItem = [UITabBarItem new];
_barItem.title = oldItem.title;
_barItem.imageInsets = oldItem.imageInsets;
_barItem.selectedImage = oldItem.selectedImage;
_barItem.badgeValue = oldItem.badgeValue;
}
self.barItem.image = _icon;
}
Then in all TabBarIOS.Item add field selectedIcon with the same url as in icon (that's no matter), set tintColor of TabBarIOS to "active" color and that's all! TabBar will be rendered with default icon color (inactive), and active icon will be in tintColor. I think that TabBar field renderAsOriginal should do this, but it not works. After all I found this solution on github https://github.com/facebook/react-native/issues/3083
Another solution (may not works in some cases):
in xCode find file RCTTabBar.m (cmd + shift + f)
find - (instancetype)initWithFrame:(CGRect)frame
add before return self:
[[UIView appearanceWhenContainedIn: [UITabBar class], nil] setTintColor: [UIColor redColor]];
[[UITabBar appearance] setSelectedImageTintColor: [UIColor greenColor]];
Restart Simulator/Device
In code redColor is color of inactive buttons, and greenColor is color of active button. For more details checkout this Unselected UITabBar color?
Edit: I found great tool if you want convert RGB to UIColor http://uicolor.xyz/

Custom controls not visible in the View

Below is my code I used to create a custom UITextField in code behind.
UITextField usernameField;
usernameField = new UITextField
{
Placeholder = "Enter your username",
BorderStyle = UITextBorderStyle.RoundedRect,
Frame = new RectangleF(10, 32, 50, 30)
};
View.AddSubview(usernameField);
But when I run my app, I dont see this anywhere. Not only this control but all the controls that I create in code behind.
If I drag the controls from toolbox onto my View it's working very fine.
What might be the cause?
Make sure that Container View is not transparent so Alpha = 1 and set background colors for appropriate controlls. Because by default its set to ClearYou can use this method to easly set background and rounded corners like in older versions of iOS
public static void MakeViewRounded(UIView view,float cornerRadius, MonoTouch.CoreGraphics.CGColor backgroundColor)
{
view.Layer.CornerRadius = cornerRadius;
view.Layer.BackgroundColor = backgroundColor;
}
Also make sure that you adding your custom controll to ViewController/View

Custom font does not render correctly when using ShowText

I have a custom view in which I am trying to draw text using a Windows font (calibri.ttf). However, I am getting different behaviour between using the DrawString & ShowText functions.
I have embedded the font as part of the app (added it to the UIAppFonts list & set it's build action to Content) and I all works fine when I use the DrawString method from my custom UIView e.g.
Code
public override void Draw (System.Drawing.RectangleF rect)
{
base.Draw (rect);
DrawString("Calibri font via DrawString", new RectangleF(10, 10, 100, 100), UIFont.FromName("Calibri", 16f));
}
Result
However, if I attempt to draw the same text this time using ShowText it appears as if the font isn't encoding the text correctly, or the character mapping is wrong.
Code
public override void Draw (System.Drawing.RectangleF rect)
{
base.Draw (rect);
var ctx = UIGraphics.GetCurrentContext();
ctx.SelectFont("Calibri", 16f, MonoTouch.CoreGraphics.CGTextEncoding.FontSpecific);
ctx.ShowTextAtPoint(10, 10, "Calibri font via ShowText using SelectFont");
}
Result
UPDATE - Here is what I get if I use MacRoman encoding instead of FontSpecific:
I have also tried loading in the font manually and using that but then I get nothing at all, it's like it doesn't recognise the font e.g.
var fontPath = NSBundle.MainBundle.PathForResource("calibri", "ttf");
var provider = new CGDataProvider(fontPath);
var font = CGFont.CreateFromProvider(provider);
var ctx = UIGraphics.GetCurrentContext();
ctx.SetFont(font);
ctx.ShowTextAtPoint(10, 20, "Calibri font via ShowText using SetFont");
I know that DrawString is UIKit & ShowText is CG (Quartz) so I understand that there may be differences. However, from what I gathered the only difference with DrawString was it corrected the issue with the difference in Offset (CG being at the bottom left/UIKit being at the top left).
NOTE - The underlying problem I have is I need to use this font to draw text onto a layer via a custom CALayerDelegate. I don't have access to the DrawString function from in there, therefore, the only way I can see to draw the text is via ShowText. Alternative solutions are welcome!
This really looks like an encoding issue. Try using CGTextEncoding.MacRoman instead of CGTextEncoding.FontSpecific (even Arial wouldn't render, as expected, with FontSpecific).
UPDATE Oct 12th
a) your last code sample won't work because Apple doc specifically states not to use SetFont and ShowText together. Quote follow:
Quartz uses font data provided by the system to map each byte of the array through the encoding vector of the current font to obtain the glyph to display. Note that the font must have been set using CGContextSelectFont. Don’t use CGContextShowText in conjunction with CGContextSetFont.
b) the CGTextEncoding.MacRoman code works with several other iPhone-supplied fonts. I'm beginning to suspect it's something about the Calibri.ttf font itself that is not supported by iOS.

Monotouch - Change View Title Background Color

Hy guys,
I have this view and I wonder how to change its title background color. This code here just change view's body background color:
var invoices = new MainInvoicesView(this);
invoices.Title = "Invoices";
invoices.View.BackgroundColor = UIColor.Gray;
Any ideas?
Regards,
Claudio
What type of view is this? UIViews do not have a Title property, so you're obviously creating a different kind of view.
If you have a UILabel called TitleLabel in your view, and it's public, you should be able to just call:
invoices.TitleLabel.BackgroundColor = UIColor.Blue;

Resources