Bug 35608 - [iOS] UIBarButtonItem(UILabel) places UILabel outside of toolbar instead of making it a toolbar button
Summary: [iOS] UIBarButtonItem(UILabel) places UILabel outside of toolbar instead of m...
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 9.0 (iOS9)
Hardware: PC Mac OS
: Highest normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-11-05 20:02 UTC by Kent Green [MSFT]
Modified: 2015-11-06 10:04 UTC (History)
8 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test case, logs & screenshot (120.50 KB, application/zip)
2015-11-05 20:02 UTC, Kent Green [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Kent Green [MSFT] 2015-11-05 20:02:54 UTC
Created attachment 13697 [details]
Test case, logs & screenshot

## Overview
From this desk case:
https://kb.xamarin.com/agent/case/232602

Customer reports that UIBarButtonItem(UILabel) places UILabel outside of toolbar instead of making it a toolbar button. In my tests, I was able to reproduce this issue in the iPhone 5 iOS 9.1 simulator. 

## Steps to reproduce
Build and deploy the attached sample app, it's one screen which shows the issue. 

## Expected Results
The body of the app should be blank, while the toolbar should show the following buttons in order from left to right:
"prev", "next", (FlexibleSpace), "Some text", (FlexibleSpace), (UploadButton)

## Actual Results
The UILabel is displayed above the toolbar, in the body of the page, rather than inside the toolbar. 

##Build Information
Reproduced in the iPhone 5 iOS 9.1 Simulator. 
=== Xamarin Studio ===

Version 5.9.8 (build 0)
Installation UUID: 8ef63a7c-1b18-40de-a334-7f78777fcb55
Runtime:
	Mono 4.0.5 ((detached/1d8d582)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400050001

=== Apple Developer Tools ===

Xcode 7.1 (9079)
Build 7B91b

=== Xamarin.iOS ===

Version: 9.1.0.27 (Enterprise Edition)
Hash: 1f068b4
Branch: master
Build date: 2015-10-27 18:59:21-0400

=== Xamarin.Android ===

Version: 5.1.9.0 (Enterprise Edition)
Android SDK: /Users/kentgreen/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)
Java SDK: /usr
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.0.2.111 (Enterprise Edition)

=== Build Information ===

Release ID: 509080000
Git revision: cc5f6e5658589ca7f46210c57fad947e75f30abd
Build date: 2015-10-21 19:27:41-04
Xamarin addins: d77f191bd7d3451adf837b85b38f2b7c60004400

=== Operating System ===

Mac OS X 10.10.5
Darwin Kents-MBP 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64

## Additional Info
Adding sample, logs & screenshot
Comment 3 Rolf Bjarne Kvinge [MSFT] 2015-11-06 06:35:43 UTC
Creating the label with an explicit size and not disabling TranslatesAutoresizingMaskIntoConstraints makes the label show up in the toolbar:

> 	resultListStatusLabel = new UILabel (new CoreGraphics.CGRect (0, 0, 320, 40));
> //	resultListStatusLabel.TranslatesAutoresizingMaskIntoConstraints = false;
Comment 4 dmitri.toropov 2015-11-06 06:43:50 UTC
Accepted as a temporary workaround, not accepted as a resolution.

If I want the label size to adapt to its content the only way is to set translatesAutoresizingMaskIntoConstraints to false and let the constraint solver use intrinsic size of the label. If the label has to be localized and I don't know the size the label has to be in advance this is the only right solution. Implemented with Objective C or Swift natively it works fine, just not with Mono.
Comment 5 John Miller [MSFT] 2015-11-06 08:45:25 UTC
@dmitri,

Could you provide an objective-c project that reproduces this behavior working as you want?
Comment 6 dmitri.toropov 2015-11-06 10:04:06 UTC
Ok, you are right: implemented the same code in Objective-C, it works exactly as in Xamarin. And I have also found the reason why: UIBarButtonItem does not inherit from UIView, therefore constraints are not applicable to it.