無論設備上設定的模式如何,我都試圖強制 UITextView 保持白色的背景顏色。目前,當設備設定為亮模式時,UITextView 的背景為白色,如果用戶更改為暗模式,則 UITextView 更改為黑色(可能是預期的行為)。
無論設備上設定的模式如何,我都想將 UITextView 的背景顏色強制為白色。
我已經嘗試在 Xcode 的 UI 和代碼中的任何地方更改此設定,但它似乎不尊重顏色集并且總是將背景顏色更改為黑色。
這是源代碼:
<view clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yI7-hV-e1x">
<rect key="frame" x="20" y="139" width="335" height="150"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="zzp-UV-fkE">
<rect key="frame" x="0.0" y="0.0" width="335" height="150"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="placeholder" value="Enter message here"/>
<userDefinedRuntimeAttribute type="color" keyPath="background.Color">
<color key="value" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="color">
<color key="value" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="UITextView.backgroundColor">
<color key="value" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="zzp-UV-fkE" secondAttribute="trailing" id="3r4-ih-LvH"/>
<constraint firstAttribute="bottom" secondItem="zzp-UV-fkE" secondAttribute="bottom" id="43N-Io-MuA"/>
<constraint firstItem="zzp-UV-fkE" firstAttribute="leading" secondItem="yI7-hV-e1x" secondAttribute="leading" id="FUG-Np-Cu1"/>
<constraint firstItem="zzp-UV-fkE" firstAttribute="top" secondItem="yI7-hV-e1x" secondAttribute="top" id="r6c-Py-iV8"/>
<constraint firstAttribute="height" constant="150" id="xlc-gd-Q43"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="7"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="layer.borderWidth">
<integer key="value" value="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="layer.borderColor">
<color key="value" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="background.Color">
<color key="value" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
這是在黑暗模式下的樣子:

這是輕模式:

我希望背景永久設定為白色。
uj5u.com熱心網友回復:
我可以通過以下方式實作
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" text="Reason for rejection" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="pzd-Bi-M3G">
...
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
...
<color key="textColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
...
</textView>
注意 - 我已經截斷了 XML 的不相關部分
uj5u.com熱心網友回復:
我能夠通過添加以下內容來解決這個問題:
UITextView.appearance.backgroundColor = [UIColor whiteColor];
UITextView.appearance.textColor = [UIColor blackColor];
出于某種原因,我無法通過 UI 實作它,不得不以編程方式實作。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/361788.html
上一篇:使用Bash腳本添加到Crontab(如果尚未存在)
下一篇:正則運算式php前瞻數字
