In my previous app now I want to Update with iOS 11 functionality. So Now I when use below code
NavigationItem.SetHidesBackButton(false, false);
var negativeSpacae = new UIBarButtonItem(UIBarButtonSystemItem.FixedSpace);
UIButton button = new UIButton(new RectangleF(0, 0, 30, 30));
button.SetImage(UIImage.FromFile("backbutton"), UIControlState.Normal);
button.TintColor = UIColor.White;
button.BackgroundColor = UIColor.Red;
var widthconstraint = button.WidthAnchor.ConstraintEqualTo(27);
var heightconstraint = button.HeightAnchor.ConstraintEqualTo(20);
widthconstraint.Active = true;
heightconstraint.Active = true;
UIBarButtonItem[] bArray = {
negativeSpacae, new UIBarButtonItem (button)
};
NavigationItem.SetLeftBarButtonItems(bArray, true);
button.TouchUpInside += (sender, e) =>
{
this.NavigationController.PopViewController(true);
};
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
{
ViewRespectsSystemMinimumLayoutMargins = false;
View.LayoutMargins = UIEdgeInsets.Zero;
}
It display below output :
In this output the button image is stretch and it display more right size.
What i am expecting is my button image is left side without stretching.
Any help will be Appreciated.
In this output the button image is stretch and it display more right size.
Cause : The image size(width * height) is great than the button size. You can check the image file in your application folder, it should be large than 27*20.
Solution : button.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.