2016-07-25 7 views
1

これは私が達成したいものです。スイフト - ラベルを含むテーブルを作成する方法

enter image description here

私はそれを自分でコーディングしようとしたが、第一の外側のビューの境界線は表示されません。

は、ここに私のコードです:

import UIKit 

class InfoTableView: UIView { 

    override func drawRect(rect: CGRect) { 

     self.backgroundColor = UIColor.whiteColor() 

     let outerBorder = UIColorCode.init(hexString: "#666666") 
    let startingTopPoint = CGPoint(x: rect.minX, y: rect.minY) 
    let endingTopPoint = CGPoint(x: rect.maxX, y: rect.minY) 

    let startingPoint = CGPoint(x: rect.minX, y: rect.maxY) 
    let endingPoint  = CGPoint(x: rect.maxX, y: rect.maxY) 

     // top 
     let tpPath = UIBezierPath() 
     tpPath.moveToPoint(startingPoint) 
     tpPath.addLineToPoint(endingTopPoint) 
     tpPath.lineWidth = 2.0 

     outerBorder.setStroke() 
     tpPath.stroke() 

     // bottom 
     let btPath = UIBezierPath() 

     btPath.moveToPoint(startingPoint) 
     btPath.addLineToPoint(endingPoint) 
     btPath.lineWidth = 2.0 

     outerBorder.setStroke() 
     btPath.stroke() 

    } 
} 

上部と下部の外側の境界線があります。しかし、下のものだけが現れます。私はどこが間違っていたのか分かりません。

+0

やあジョン、のUITableViewに見てみてください、それは – xmhafiz

+1

@ジョン代わりに車輪の再発明の動的なデータを持っているカスタマイズと簡単です、私の事あなたはのUITableViewに試してみるとのUITableViewCellをカスタマイズしてみてください。わずかなカスタマイズと少ないコーディングで出力を得ることができます。 –

答えて

0

私はあなたのコードを少し編集しました。それがあなたのために働く場合に試してください。

override func drawRect(rect: CGRect) { 
     // Drawing code 
     self.backgroundColor = UIColor.whiteColor() 
     let outerBorder = UIColor.redColor() 
     let lineWidth : CGFloat = 2.0 
     let insetRect = rect.insetBy(dx: lineWidth/2, dy: lineWidth/2) 
     let startingTopPoint = CGPointMake(insetRect.origin.x,insetRect.origin.y) 
     let endingTopPoint = CGPoint(x: insetRect.maxX, y: insetRect.minY) 

     let startingPoint = CGPoint(x: insetRect.minX, y: insetRect.maxY) 
     let endingPoint  = CGPoint(x: insetRect.maxX, y: insetRect.maxY) 

     // top 
     let tpPath = UIBezierPath() 
     tpPath.moveToPoint(startingTopPoint) 
     tpPath.addLineToPoint(endingTopPoint) 
     tpPath.lineWidth = 2.0 

     outerBorder.setStroke() 
     tpPath.stroke() 

     // bottom 
     let btPath = UIBezierPath() 

     btPath.moveToPoint(startingPoint) 
     btPath.addLineToPoint(endingPoint) 
     btPath.lineWidth = 2.0 

     outerBorder.setStroke() 
     btPath.stroke() 
    } 
関連する問題