私は、RootTabControllerのタブであるViewControllerにCollectionViewを持っています。 .xibとして設計され、このCollectionViewのCell:私はCollectionViewCellのUILabelフォントをXamarin StudioのC#で変更できません
XIB UI:
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="GridBoxCell" id="cZE-iV-UFb" customClass="GridBoxViewCell">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</view>
<color key="backgroundColor" red="0.20000000000000001" green="0.031372549019607843" blue="0.38039215686274508" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="4" firstAttribute="top" secondItem="cZE-iV-UFb" secondAttribute="top" id="10"/>
<constraint firstItem="4" firstAttribute="leading" secondItem="cZE-iV-UFb" secondAttribute="leading" id="11"/>
<constraint firstAttribute="bottom" secondItem="4" secondAttribute="bottom" id="12"/>
<constraint firstAttribute="trailing" secondItem="4" secondAttribute="trailing" id="13"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<real key="value" value="5"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<outlet property="Value_Label" destination="4" id="name-outlet-4"/>
</connections>
</collectionViewCell>
</objects>
私は、デバイスの画面サイズに基づいてコードを経由してUıLabelのフォントを変更しようとしていますコンストラクタステージのポイントでCollectionViewに追加する前にXibをロードしている間:
XIBコード:
protected GridBoxViewCell(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
var selectback_view = new UIView(); // Selectedbackground UIview.
selectback_view.BackgroundColor = UIColor.FromRGB(117, 24, 73); // pink Color
SelectedBackgroundView = selectback_view; // Selected background assigned.
if (UIDevice.CurrentDevice.Model.Contains("iPad")) // If a iPad
{
Value_Label.Font = UIFont.FromName(".SFUIText", 20f); // Increse font width.
}
else // If a iPhone or iPod Touch
{
if (UIScreen.MainScreen.Bounds.Width == 414 && UIScreen.MainScreen.Bounds.Height == 736) // a iPhone Plus 5.5 in point
{
Value_Label.Font = UIFont.FromName(".SFUIText", 16f); // Increse font width.
}
if (UIScreen.MainScreen.Bounds.Width == 375 && UIScreen.MainScreen.Bounds.Height == 667) // a iPhone 4.7 in point
{
Value_Label.Font = UIFont.FromName(".SFUIText", 14f); // Increse font width.
}
}
}
しかし、この行はとNullReferenceExceptionを与える:
Value_Label.Font = UIFont.FromName( "SFUIText"、14F)。 // Increseフォントの幅。
UITextBoxで入力された値をLinkedListに基づいて追加したUIBarButton "Done"は、UITextBoxで入力された値を追加します。 CollectionViewのデータを更新すると四角形が表示されます。
これは最初から働いていましたが、現在は機能していません。私はなぜそれが今働かなかったのか理解できませんでした。また、xibは問題なしで動いています4 "SEのようなiPhone、私はそれのための制約をコードしないので、デフォルトのフォントを使用します。私に。ありがとう。
それは、先端@Jonah Hulselmansに感謝を実行します:) –