2017-01-24 2 views
0

나는 안드로이드 애플 리케이션을 IOS로 변환하기 시작했고, 어떻게 안드로이드 XML 드로어 블을 변환 할 수 있는지 궁금해하고 있었다. 목표는 텍스처가 늘어나지 않도록 x 및 y 위치의 모양을 사용하여 텍스처를 만들 수 있도록하는 것입니다. IOS에서 안드로이드 drawable과 비슷한 것이 있습니까? 만약 IOS에서 드로어 블에서 생성 된 텍스쳐를 어떻게 사용합니까? 예를 들어 아래의 텍스트 상자에 drawable을 어떻게 변환합니까?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> 
+0

: 안드로이드 드로어 블 Drawable 같은 XML에 아니지만, 기능은 매우 당신이 문제의 안드로이드 그리기의 UI components.The 변환을위한 텍스처를 만드는 기본 모양을 사용할 수있는 안드로이드 드로어 블 Drawable 유사 아래에 표시된다 아마도'UIBezierPath' (https://developer.apple.com/reference/uikit/uibezierpath)를 살펴 봐야 할 것입니다. 구현면에서 유사하지는 않지만 결과는 비슷합니다. – Chackle

답변

0

UIBezierPath는 내가 찾은 Android Drawables에 가장 가까운 것입니다.

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() 
} 
} 
관련 문제