【发布时间】:2021-12-28 08:23:35
【问题描述】:
我试图强制 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>
这是暗模式下的样子:
这是灯光模式:
我希望将背景永久设置为白色。
【问题讨论】:
标签: xcode uitextview