I used this code in AppDelegate,
UIBarButtonItem.Appearance.SetBackButtonTitlePositionAdjustment (new UIOffset (-100, -60), UIBarMetrics.Default);
But it position is changed to bottom. I have attached the result screenshot.
Solution1 : set Title Color instead of Title Position
UITextAttributes attribute = new UITextAttributes {TextColor = UIColor.Clear };
UIBarButtonItem.Appearance.SetTitleTextAttributes(attribute, UIControlState.Normal);
Solution2 : set horizontal offset only.
UIBarButtonItem.Appearance.SetBackButtonTitlePositionAdjustment (new UIOffset (-100, 0), UIBarMetrics.Default);
Related
In my project I want to add logo to navigation bar. In android by using custom renderer I have placed the logo to navigation bar. But i don't know how to set the logo in navigation bar at globally in ios xamarin forms. Anyone give suggestion how to solve this.
I have tried like this,
NavigationPage.SetTilteIcon(this, "icon.png"); // But image is not display
Icon placement Reference Screenshot
You can try by setting the icon as:
Application.Current.MainPage = new NavigationPage(new FirstPageName() { Icon="icon.png"});
While navigating to another page you can write this as:
this.Navigation.PushAsync(new SecondPageName() { Icon="icon.png"});
Make sure you have the icon image in iOS project folder.
You can try custom renderer for a single page. But we can't set it at globally. Because in iOS every ViewController has a NavigationItem, we should set it when we need.
Here is some code about how to set NavigationItem in page renderer:
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
UIView leftView = new UIView(new CGRect(0, 0, 100, 40));
UIImageView imgView = new UIImageView(UIImage.FromBundle("icon.png"));
imgView.Frame = new CGRect(0, 5, 30, 30);
leftView.AddSubview(imgView);
UILabel label = new UILabel(new CGRect(30, 10, 70, 20));
label.Text = "page Title";
leftView.AddSubview(label);
//add event
UITapGestureRecognizer tap = new UITapGestureRecognizer((sender) =>
{
});
leftView.AddGestureRecognizer(tap);
leftItem = new UIBarButtonItem(leftView);
NavigationController.TopViewController.NavigationItem.SetLeftBarButtonItem(leftItem, true);
}
Please notice that put this image source in iOS's project.
Also if you do want to show this icon image in each page. Try to create a base page and construct this renderer for it. Then let your page inherit from it.
any ideas how to prepare such an element as at the picture ?
I need 5 buttons to be there so i could swipe through them but only 3 one them are visible all the time. I need this to work on android and ios in xamarin forms.
Try this Add ScrollView and set it's orientation to horizontal
ScrollView = new ScrollView
{
Orientation = ScrollOrientation.Horizontal
};
//ScrollView.Scrolled += ScrollView_Scrolled;
ItemsStackLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal,
Padding = new Thickness(0),
Spacing = 0,
HorizontalOptions = LayoutOptions.FillAndExpand
};
ScrollView.Content = ItemsStackLayout;
you can set the width of the elements inside 1/3 of the view width
FYI I use the same in my app
I wanted chat application type user interface in my app & i am targeting android and iOS.
I am using Xamarin.Forms.Editor for reply
Editor _replyEntry = new Editor
{
HorizontalOptions = LayoutOptions.FillAndExpand,
TextColor = Color.Black
}
in this case the editor height remains constant and allows scrolling and editor does not expands
Then i used InvalidateMeasure()
_replyEntry .TextChanged += (sender, e) => { this.InvalidateMeasure(); };
in this case editor expands as when the text requires more space but does not allow scroll inside editor and if user types long message then editor does not allows scroll and text goes behind the keyboard and not visible to user
Is there any way to enable scroll and give max height to edit either in xamarin.forms of by writing custom renderer
Thanks
Here is my code
public class abc : ContentPage
{
public abc()
{
Image attchment = new Image
{
Source = "attachment.png",
HorizontalOptions = LayoutOptions.Start
};
Editor _replyEntry = new Editor
{
HorizontalOptions = LayoutOptions.FillAndExpand,
TextColor = Color.Black,
};
Button _sendButton = new Button
{
Text = "Send",
TextColor = Color.Black,
BackgroundColor = Color.Transparent,
HorizontalOptions = LayoutOptions.End
};
StackLayout replyStack = new StackLayout
{
Orientation = StackOrientation.Horizontal,
Padding = new Thickness(10),
Spacing = 10,
VerticalOptions = LayoutOptions.End,
Children = { attchment, _replyEntry, _sendButton }
};
Content = replyStack;
}
}
It looks like you will have to use a custom renderer to achieve what you are wanting.
There is a post here that has pretty much the same thing with what you are trying to achieve for Android.
In that demo it has an expanding multi-line EditText control (android:singleLine="false"), with only vertical scrollbars (android:scrollbars="vertical"), whilst disabling the horizontal scrollbars (android:scrollHorizontally="false").
You need to ensure the Editor' parent is expanding, then the editor will automatically expand too. If you make an empty contentpage and add an Editor, the is will just expand. If you place it inside a stacklayout, the you need to ensure that the stacklayout is expanding.
I have Frame with Grid in content. When i added contentWiew (with content) to Grid there are two options:
1. If contentWiew have BackgroundColor = "Transparent" then when i click to the contentWiew pressing happen in Frame (contentWiew skiped through it).
2. If contentWiew have BackgroundColor = NotTransparent (Red,Yellow) then when i click to the contentWiew pressing happen in contentWiew ().
Part of the code:
Label mainText = new Label { Text = "TestText", FontSize = 14 };
var contntView = new ContentView () { BackgroundColor = Color.Transparent , HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Start };
contntView.Content = mainText;
mainGrid.Children.Add (contntView,0,1);
I need to do exactly the turnover =) When ContentView is Transparent - catch click. When ContentView is not Transparent - skip click to Frame.
How can I control this process, regardless of BackgroundColor?
You can partially control this process using any View's InputTransparent property. If it's set to true, the view will be transparent to touch events.
What's the proposed way to add space to layouts in Xamarin.Forms?
One way would be to add a Frame with no children like so:
new Frame {
BackgroundColor = Color.White,
HeightRequest = 1,
MinimumHeightRequest = 1,
HasShadow = false
}
Unfortunately, HeightRequest and MinimumHeightRequest get ignored.
Does a better way exist?
You could put your controls inside layouts (like frame, scroll view, stack panel) and use Padding property:
this.stackPanel = new StackLayout ()
{
Padding = new Thickness (8, 8)
};
var scrollView = new ScrollView ()
{
Content = stackPanel,
Padding = new Thickness (1, 2, 3, 4)
};
var frame = new Frame ()
{
Padding = new Thickness (8)
};
If you want space between two buttons for example, I believe this would do the trick. The first one adds 10 to bottom padding, the second adds 10 to top padding for total of 20.
var frame1 = new Frame ()
{
Padding = new Thickness (0,0,0,10),
Content = new Button()
};
var frame2 = new Frame ()
{
Padding = new Thickness (0,10,0,0),
Content = new Button()
};
Most Xamarin.Forms Layouts supports adding space between elements:
StackLayout has a Spacing property,
Grid has RowSpacing and ColumnSpacing properties,
...
Now, if you want to add spacing at a particular place, the way to to it is to include a BoxView:
myStackLayout.Children.Add (new BoxView {Color = Color.Transparent, HeightRequest = 5});
You can also wrap your content in a Frame or ContentView, but it adds padding to the content instead of adding space (although the effect will be the same).
What I do worked perfectly for me:
Suppose you want to distribute 2 Labels evenly on a horizontal StackLayout:
new StackLayout
{
Orientation = StackOrientation.Horizontal,
HorizontalOptions=LayoutOptions.CenterAndExpand,
Spacing = 0, // <- Very important!!
Children = {
new Label { Text = "Label 1" },
new BoxView { HorizontalOptions = LayoutOptions.FillAndExpand }, // <- the clever part
new Label { Text = "Label 2" }
}
};
Summary
By inserting BoxViews that fill the remaining space ("FillAndExpand") between your views, your views appear evenly distributed.
By setting Spacing = 0, you don't get extra space between your views.
Try:
myFrame.TranslateX=10;
myFrame.TranslateY=10;
I wanted to share a screenshot in conjunction with Lay González's answer but the edit queue was full->
To get dynamic spacing similar to CSS "Space-Between" in Xamarin you can insert filler views between your views that actually have content.
Here is an example:
Omit the filler view after the last "actual" view so that the view you want is at the end (the "-50" label at the bottom in the example).