0

RootTabController의 탭인 ViewController에 CollectionView가 있습니다.Xamarin Studio에서 C#으로 CollectionViewCell의 UILabel 글꼴을 변경할 수 없습니다.

enter image description here

XIB UI :이 CollectionView의 셀은 .xib로 설계

<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> 

나는 장치 화면 크기에 따라 코드를 통해 UILabel의의 글꼴을 변경하기 위해 노력하고있어 Xbu가 CollectionView에 추가되기 전에로드하는 동안 생성자 단계에서 :

,691,363,210

XIB 코드 :

Value_Label.Font = UIFont.FromName (". SFUIText"을, 14F);

 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이 범 // Increse 글꼴 너비.

UITextBox에서 입력 한 값을 LinkedList를 기반으로 GridViewDataSource에 추가하는 키보드 상단에 UIBarButton "Done"이 추가되었습니다. CollectionView의 데이터를 새로 고치면 사각형이 나타납니다.

처음에는 작동했지만 지금은 작동하지 않습니다. 왜 지금 작동하지 않았는 지 알 수 없었습니다. 또한 xib는 문제없이 실행됩니다. 4 "SE와 같은 iPhone은 제약 조건을 코딩하지 않기 때문에 기본 글꼴을 사용합니다. 도움이된다면 기쁠 것입니다. 나. 감사합니다.

답변

0

당신은 awakeFromNib 방법을 무시하고 그 방법에 글꼴을 할당해야합니다.

그것은 실행
+0

, 덕분에 팁 @Jonah Hulselmans에 대한 :) –