Get Navigation bar height in xamarin forms? - xamarin.ios

I am working on a project where i need to get the navigation bar height.I am getting the whole screen height using:
Helpers.ApplicationContext.ScreenHeight = (int)Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density;
Helpers.ApplicationContext.ScreenWidth = (int)Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density;
But I am not able to get the navigation bar height.
Can any one please suggest an idea to get the navigation bar height of my page.
Thanks in advance.

For iOS This may help you :
var navbarHeight = YourViewControllerInstance.NavigationController?.NavigationBar.Frame.Height;
For Android :
TypedArray styledAttributes = this.Theme.ObtainStyledAttributes(
new int[] { Android.Resource.Attribute.ActionBarSize });
var actionbarHeight = (int) styledAttributes.GetDimension(0, 0);
styledAttributes.recycle();
Above example gives Height in Pixel. Please find more refined sample as below which provide height in Pixel as well as DP:
TypedValue tv = new TypedValue();
int actionBarHeightInPixel = 0;
int actionBarHeightInDP = 0;
DisplayMetrics metrics = Resources.DisplayMetrics;
if (Theme.ResolveAttribute(Resource.Attribute.actionBarSize, tv, true))
{
actionBarHeightInPixel = TypedValue.ComplexToDimensionPixelSize(tv.Data, metrics);
actionBarHeightInDP = actionBarHeightInPixel / (int)metrics.Density;
}

Related

How do I change font sizes in Heaps?

I'm currently coding in Haxe with Heaps and was checking on how to display text. One thing I want to do is give different font sizes to different texts. Naturally, I declared two Font instances and resized one of them. However, both texts are resized and I cannot manage to have them resize independently. How should I resize font sizes in Heaps?
class Main extends hxd.App{
override function init(){
var font : h2d.Font = hxd.res.DefaultFont.get();
var font2 : h2d.Font = hxd.res.DefaultFont.get();
font2.resizeTo(23);
var tf = new h2d.Text(font);
var tf2 = new h2d.Text(font2);
tf.text = "Hello World\nHeaps is great!";
tf.textColor = 0x00FF00;
tf.x = 100;
tf.y = 100;
tf.textAlign = Center;
tf2.text = "Hello World\nHeaps is great!";
tf2.textColor = 0x00FF00;
tf2.x = 300;
tf2.y = 300;
tf2.textAlign = Center;
s2d.addChild(tf);
s2d.addChild(tf2);
static function main(){
new Main();
}
}
The approach taken does not work because DefaultFont.get() caches the result.
You could either:
Copy the second font by doing var font2 : h2d.Font = font.clone() so that it gets its own properties.
Adjust scaleX and scaleY of Text.

How can I adjust the NavigationBar height to show an inserted SubView

I am trying to insert a sub view in the NavigationBar that needs to appear on all screens across the app. The code used to insert is below
ConnectionBarController statusBar = (ConnectionBarController)UIStoryboard.FromName("Main", null).InstantiateViewController("ConnectionBarController");
if (NavigationController != null)
{
this.NavigationController.View.Add(statusBar.View);
// var frame = this.NavigationController.View.Frame;
// frame.Height += ConnectionBarController.FrameHeight;
// this.NavigationController.View.Frame = frame;
}
It seems to appear, but the NavBar is cut off. Any suggestions on how to get this working?
I cant post a screen shot, as I am short of 2 reputations. Let me know if anyone needs to see the screenshot

tapku calendar color

I am using a TapkuMonthCalendarViewController in my application and when the calendar loads the color scheme of the calendar is not appearing normal on the simulator. Anyone else experience this?
I haven't messed with trying to set the background of anything and I have used this calendar before in other applications and it has never acted like this.
Any advice would be greatly appreciated.
This is the calendar view i see http://i.imgur.com/IwT9s.png
EDIT: I realized I forgot to include the bundle into my project! So this is the solution for all future tapku users.
You change calendar background than you can change the Calendar tile image .
OR You put this code on drawRect Method.
- (void) drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
//UIImage *tile = [UIImage imageWithContentsOfFile:TKBUNDLE(#"TapkuLibrary.bundle/Images/calendar/Month Calendar Date Tile.png")];
CGRect r = CGRectMake(0, 0, 46, 44);
//CGContextDrawTiledImage(context, r, tile.CGImage);
if(today > 0){
int pre = firstOfPrev > 0 ? lastOfPrev - firstOfPrev + 1 : 0;
int index = today + pre-1;
CGRect r =[self rectForCellAtIndex:index];
r.origin.y -= 7;
//[[UIImage imageWithContentsOfFile:TKBUNDLE(#"TapkuLibrary.bundle/Images/calendar/Month Calendar Today Tile.png")] drawInRect:r];
}
}

Horizontal Scrollview to Swipe through coredata objects

I have an iOS app built on CoreData with tableviews and detailviews of the objects.
When in the detailview I would like to swipe horizontally to get the detail view of the next object.
I found PageControl and scrollview. But this is going to be for over 100 objects in the model.
Does anyone have a good sample of this or resource on how to do this.
Thanks
Michael
You could make individual views for each Core Data Object, then place those views on a UIScrollView.
You would need to set the contentSize:
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * allYourViews.count, scrollView.frame.size.height);
Then loop over all your views and add them to the scrollView:
for(int i = 0; i < allYourViews.count; i++) {
CGRect frame;
frame.origin.x = scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = scrollView.frame.size;
if(allYourViews.count > 0) {
UIView* someView = (UIView *)allYourViews[i];
someView.frame = frame;
[scrollView addSubview:someView];
}
}
For more information and how to make it scroll nicely, check this tutorial:
http://www.iosdevnotes.com/2011/03/uiscrollview-paging/
( I don't know how this will perform :-)

Buttons in LinearLayout not filling entire space programmatically

So I have a LinearLayout in horizontal mode which I add buttons to at random times in code and I like them all to fill up the space equally.
This is my current code so far:
layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.FILL;
and I add it to my view here:
linearLayout.addView(button, layoutParams);
All it does is add the buttons as if it was wrap_content and not expanding their width to fill up the available space as in the buttons look left justified.
I also have tried linearLayout.setGravity(Gravity.FILL_HORIZONTAL); and
linearLayout.setWeightSum(++weightSum);
linearLayout.addView(button, layoutParams);
where layoutParams in this case is:
layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT, 1);
I also tried setting the layout width to zero per answers to other questions.
Am I missing another technique?
Edit: I figured it out, I forgot to set the width of the LinearLayout to match_parent instead of wrap_content.
Button's background has "margins" so they will always have gaps even if there's no space between buttons. You have to change background to your own image which doesn't have these margins.
EDIT: You should use weights for buttons.
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
0, LayoutParams.WRAP_CONTENT);
params.weight = 1;
for( int i = 0; i < 5; ++i) {
Button button = new Button(this);
button.setText("Button" + (i + 1));
linearLayout.addView(button, params);
}

Resources