如何将 Android 个可绘制对象转换为 IOS?
How to convert Android drawables to IOS?
我刚刚开始尝试将我的 Android 应用程序转换为 IOS,并且想知道如何转换我的 Android XML 可绘制对象。目标是能够使用具有 x 和 y 位置的形状创建纹理,这样纹理就不会被拉伸。在 IOS 中是否有与 Android 可绘制对象类似的东西?如果不是,我将如何使用从 IOS 中的可绘制对象创建的纹理?例如,我将如何转换下面文本框的可绘制对象?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="10dp" android:left="0dp" android:bottom="0dp" android:right="0dp">
<shape
android:shape="rectangle">
<size
android:height="13dp"
android:width="46dp"
/>
<solid
android:color="@color/grey"
/>
</shape>
</item>
<item android:top="0dp" android:left="0dp" android:bottom="10dp" android:right="0dp">
<shape
android:shape="rectangle">
<size
android:height="13dp"
android:width="46dp"
/>
<solid
android:color="@color/very_light_grey"
/>
</shape>
</item>
<item android:top="0dp" android:left="2dp" android:bottom="0dp" android:right="2dp">
<shape
android:shape="rectangle">
<size
android:height="13dp"
android:width="46dp"
/>
<solid
android:color="@color/grey"
/>
</shape>
</item>
<item android:top="1dp" android:left="3dp" android:bottom="3dp" android:right="3dp">
<shape
android:shape="rectangle">
<size
android:height="20dp"
android:width="40dp"
/>
<solid
android:color="@color/white"
/>
</shape>
</item>
</layer-list>
UIBezierPath 是我能找到的最接近 Android Drawable 的东西。虽然它不像 Android Drawables 在 XML 中,但功能与 Android Drawables 非常相似,您可以在其中使用基本形状为 UI components.The 创建纹理问题中Android Drawable的转换如下:
import Foundation
import UIKit
class CustomUIInputText : UITextField{
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
}
override init(frame: CGRect) {
super.init(frame: frame)
}
override func draw(_ rect: CGRect) {
let darkGrey = ColorUtilities.hexStringToUIColor(hex: "808080")
let lightGrey = ColorUtilities.hexStringToUIColor(hex: "efefef")
let lightGreyRect = UIBezierPath(rect: rect)
let width = rect.size.width
let height = rect.size.height
let yValue = rect.origin.y
let xValue = rect.origin.x
lightGrey.setFill()
lightGreyRect.fill()
let darkGreyRect = UIBezierPath(rect: CGRect(x: xValue, y:yValue + ((2 * height)/3), width: width, height: height/3))
darkGrey.setFill()
darkGreyRect.fill()
let darkGreyRect2 = UIBezierPath(rect: CGRect(x: xValue+3, y:yValue, width: width - 6, height: height))
darkGrey.setFill()
darkGreyRect2.fill()
let whiteRect = UIBezierPath(rect: CGRect(x: xValue + 4, y:yValue + 1, width: width - 8, height: height - 4))
UIColor.white.setFill()
whiteRect.fill()
}
}
我刚刚开始尝试将我的 Android 应用程序转换为 IOS,并且想知道如何转换我的 Android XML 可绘制对象。目标是能够使用具有 x 和 y 位置的形状创建纹理,这样纹理就不会被拉伸。在 IOS 中是否有与 Android 可绘制对象类似的东西?如果不是,我将如何使用从 IOS 中的可绘制对象创建的纹理?例如,我将如何转换下面文本框的可绘制对象?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="10dp" android:left="0dp" android:bottom="0dp" android:right="0dp">
<shape
android:shape="rectangle">
<size
android:height="13dp"
android:width="46dp"
/>
<solid
android:color="@color/grey"
/>
</shape>
</item>
<item android:top="0dp" android:left="0dp" android:bottom="10dp" android:right="0dp">
<shape
android:shape="rectangle">
<size
android:height="13dp"
android:width="46dp"
/>
<solid
android:color="@color/very_light_grey"
/>
</shape>
</item>
<item android:top="0dp" android:left="2dp" android:bottom="0dp" android:right="2dp">
<shape
android:shape="rectangle">
<size
android:height="13dp"
android:width="46dp"
/>
<solid
android:color="@color/grey"
/>
</shape>
</item>
<item android:top="1dp" android:left="3dp" android:bottom="3dp" android:right="3dp">
<shape
android:shape="rectangle">
<size
android:height="20dp"
android:width="40dp"
/>
<solid
android:color="@color/white"
/>
</shape>
</item>
</layer-list>
UIBezierPath 是我能找到的最接近 Android Drawable 的东西。虽然它不像 Android Drawables 在 XML 中,但功能与 Android Drawables 非常相似,您可以在其中使用基本形状为 UI components.The 创建纹理问题中Android Drawable的转换如下:
import Foundation
import UIKit
class CustomUIInputText : UITextField{
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
}
override init(frame: CGRect) {
super.init(frame: frame)
}
override func draw(_ rect: CGRect) {
let darkGrey = ColorUtilities.hexStringToUIColor(hex: "808080")
let lightGrey = ColorUtilities.hexStringToUIColor(hex: "efefef")
let lightGreyRect = UIBezierPath(rect: rect)
let width = rect.size.width
let height = rect.size.height
let yValue = rect.origin.y
let xValue = rect.origin.x
lightGrey.setFill()
lightGreyRect.fill()
let darkGreyRect = UIBezierPath(rect: CGRect(x: xValue, y:yValue + ((2 * height)/3), width: width, height: height/3))
darkGrey.setFill()
darkGreyRect.fill()
let darkGreyRect2 = UIBezierPath(rect: CGRect(x: xValue+3, y:yValue, width: width - 6, height: height))
darkGrey.setFill()
darkGreyRect2.fill()
let whiteRect = UIBezierPath(rect: CGRect(x: xValue + 4, y:yValue + 1, width: width - 8, height: height - 4))
UIColor.white.setFill()
whiteRect.fill()
}
}